From 776f6eae7a3316ec9e1a389015444527937d4b29 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:25:43 +0000 Subject: [PATCH 1/6] Update Tests/VTEX.Integration.Tests/VTEX.Integration.Tests.csproj --- .../VTEX.Integration.Tests.csproj | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/VTEX.Integration.Tests.csproj diff --git a/Tests/VTEX.Integration.Tests/VTEX.Integration.Tests.csproj b/Tests/VTEX.Integration.Tests/VTEX.Integration.Tests.csproj new file mode 100644 index 00000000..0c3bc9f6 --- /dev/null +++ b/Tests/VTEX.Integration.Tests/VTEX.Integration.Tests.csproj @@ -0,0 +1,15 @@ + + + + net5.0 + + + + + + + + + + + \ No newline at end of file From 65a7dca64683f65a93bbfefb7c2633455665383e Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:25:53 +0000 Subject: [PATCH 2/6] Update Tests/VTEX.Integration.Tests/WireMockServerFixture.cs --- .../WireMockServerFixture.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/WireMockServerFixture.cs diff --git a/Tests/VTEX.Integration.Tests/WireMockServerFixture.cs b/Tests/VTEX.Integration.Tests/WireMockServerFixture.cs new file mode 100644 index 00000000..e018207f --- /dev/null +++ b/Tests/VTEX.Integration.Tests/WireMockServerFixture.cs @@ -0,0 +1,20 @@ +using System; +using WireMock.Server; +using WireMock.Settings; + +public class WireMockServerFixture : IDisposable +{ + public WireMockServer Server { get; } + + public WireMockServerFixture() + { + Server = WireMockServer.Start(new WireMockServerSettings + { + Urls = new[] { "http://localhost:9091" }, + StartAdminInterface = true, + ReadStaticMappings = true + }); + } + + public void Dispose() => Server.Stop(); +} \ No newline at end of file From 75332c58f15f7fc654a4d60c92c55abd93b71258 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:26:06 +0000 Subject: [PATCH 3/6] Update Tests/VTEX.Integration.Tests/ErpServiceTests.cs --- .../VTEX.Integration.Tests/ErpServiceTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/ErpServiceTests.cs diff --git a/Tests/VTEX.Integration.Tests/ErpServiceTests.cs b/Tests/VTEX.Integration.Tests/ErpServiceTests.cs new file mode 100644 index 00000000..375e5f6c --- /dev/null +++ b/Tests/VTEX.Integration.Tests/ErpServiceTests.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; +using Xunit; + +public class ErpServiceTests : IClassFixture +{ + private readonly WireMockServerFixture _fixture; + + public ErpServiceTests(WireMockServerFixture fixture) + { + _fixture = fixture; + } + + [Fact] + public async Task ShouldHandleSuccessfulResponse() + { + // Arrange + _fixture.Server + .Given(Request.Create().WithPath("/api/orders").UsingGet()) + .RespondWith(Response.Create().WithStatusCode(200).WithBody("{ \"orderId\": \"12345\" }")); + + // Act + var result = await _service.GetOrderAsync("12345"); + + // Assert + Assert.Equal("12345", result.OrderId); + } +} \ No newline at end of file From 321ee41dd01bbe3e73162951bb9636de035b6a5b Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:26:16 +0000 Subject: [PATCH 4/6] Update Tests/VTEX.Integration.Tests/SnapshotTests.cs --- Tests/VTEX.Integration.Tests/SnapshotTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/SnapshotTests.cs diff --git a/Tests/VTEX.Integration.Tests/SnapshotTests.cs b/Tests/VTEX.Integration.Tests/SnapshotTests.cs new file mode 100644 index 00000000..a93dfb8a --- /dev/null +++ b/Tests/VTEX.Integration.Tests/SnapshotTests.cs @@ -0,0 +1,19 @@ +using System.Threading.Tasks; +using Snapshooter.Xunit; +using Xunit; + +public class SnapshotTests +{ + [Fact] + public async Task ShouldMatchExpectedResponse() + { + // Arrange + var expectedResponse = new { OrderId = "12345" }; + + // Act + var actualResponse = await _service.GetOrderAsync("12345"); + + // Assert + actualResponse.Should().MatchSnapshot(); + } +} From e83c3f7604b1e1b35dfbe603dec801c67cd6f9e9 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:26:30 +0000 Subject: [PATCH 5/6] Update Tests/VTEX.Integration.Tests/OrderGenerator.cs --- .../VTEX.Integration.Tests/OrderGenerator.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/OrderGenerator.cs diff --git a/Tests/VTEX.Integration.Tests/OrderGenerator.cs b/Tests/VTEX.Integration.Tests/OrderGenerator.cs new file mode 100644 index 00000000..332baaae --- /dev/null +++ b/Tests/VTEX.Integration.Tests/OrderGenerator.cs @@ -0,0 +1,21 @@ +using Bogus; + +public class OrderGenerator +{ + public static Order CreateFakeOrder() + { + var faker = new Faker() + .RuleFor(o => o.OrderId, f => f.Random.Guid().ToString()) + .RuleFor(o => o.CustomerName, f => f.Name.FullName()) + .RuleFor(o => o.Amount, f => f.Finance.Amount()); + + return faker.Generate(); + } +} + +public class Order +{ + public string OrderId { get; set; } + public string CustomerName { get; set; } + public decimal Amount { get; set; } +} \ No newline at end of file From dc0bbc946e16be54fd009b0cc3c5fb8fbd477741 Mon Sep 17 00:00:00 2001 From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com> Date: Fri, 27 Dec 2024 00:26:43 +0000 Subject: [PATCH 6/6] Update Tests/VTEX.Integration.Tests/OrderServiceTests.cs --- .../OrderServiceTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Tests/VTEX.Integration.Tests/OrderServiceTests.cs diff --git a/Tests/VTEX.Integration.Tests/OrderServiceTests.cs b/Tests/VTEX.Integration.Tests/OrderServiceTests.cs new file mode 100644 index 00000000..457bc7fb --- /dev/null +++ b/Tests/VTEX.Integration.Tests/OrderServiceTests.cs @@ -0,0 +1,29 @@ +using System.Threading.Tasks; +using NSubstitute; +using Xunit; + +public class OrderServiceTests +{ + private readonly IOrderRepository _orderRepository; + private readonly OrderService _orderService; + + public OrderServiceTests() + { + _orderRepository = Substitute.For(); + _orderService = new OrderService(_orderRepository); + } + + [Fact] + public async Task ShouldReturnOrder() + { + // Arrange + var fakeOrder = OrderGenerator.CreateFakeOrder(); + _orderRepository.GetOrderAsync(Arg.Any()).Returns(Task.FromResult(fakeOrder)); + + // Act + var result = await _orderService.GetOrderAsync(fakeOrder.OrderId); + + // Assert + Assert.Equal(fakeOrder.OrderId, result.OrderId); + } +} \ No newline at end of file