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 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 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 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(); + } +} 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 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