public async Task The_Customer_Is_Added_To_The_Datastore() { string id = Guid.NewGuid().ToString(); const string firstName = nameof(firstName); const string lastName = nameof(lastName); DateTime dateOfBirth = DateTime.UtcNow; var customer = new Api.Customer { FirstName = firstName, LastName = lastName, DateOfBirth = dateOfBirth }; var expectedCustomers = new Entities.Customer[] { new Entities.Customer { DateOfBirth = dateOfBirth, FirstName = firstName, Id = id, LastName = lastName } }; FakeIdentityGenerator identityGenerator = new FakeIdentityGenerator() .WithGeneratedIdentities(id); AddCustomerFixture sut = new AddCustomerFixture() .WithIdentityGenerator(identityGenerator); await sut.AddCustomer(customer); sut.PostTestCustomers.Should().BeEquivalentTo(expectedCustomers); }
public Entities.Customer Map(Api.Customer customer) { return(new Entities.Customer { DateOfBirth = customer.DateOfBirth.Value, FirstName = customer.FirstName, Id = customer.Id, LastName = customer.LastName }); }
public async Task <IActionResult> UpdateCustomer(Api.Customer customer) { IServiceProvider provider = TestServiceProvider.CreateProvider(); using (IServiceScope scope = provider.CreateScope()) { await SeedRepository(scope.ServiceProvider); CustomersController controller = scope.ServiceProvider.GetRequiredService <CustomersController>(); IActionResult result = await controller.UpdateCustomer(customer, scope.ServiceProvider.GetRequiredService <UpdateCustomerCommand>()); await SnapshotRepository(scope.ServiceProvider); return(result); } }
public async Task A_Success_Response_Is_Returned() { string id1 = Guid.NewGuid().ToString(); string id2 = Guid.NewGuid().ToString(); const string firstName1 = nameof(firstName1); const string firstName1a = nameof(firstName1a); const string firstName2 = nameof(firstName2); const string lastName1 = nameof(lastName1); const string lastName1a = nameof(lastName1a); const string lastName2 = nameof(lastName2); DateTime dateOfBirth1 = DateTime.UtcNow; DateTime dateOfBirth1a = dateOfBirth1.AddDays(-1); DateTime dateOfBirth2 = dateOfBirth1.AddDays(-2); var existingCustomers = new Entities.Customer[] { new Entities.Customer { DateOfBirth = dateOfBirth1, FirstName = firstName1, Id = id1, LastName = lastName1 }, new Entities.Customer { DateOfBirth = dateOfBirth2, FirstName = firstName2, Id = id2, LastName = lastName2 }, }; var updateCustomer = new Api.Customer { DateOfBirth = dateOfBirth1a, FirstName = firstName1a, Id = id1, LastName = lastName1a }; UpdateCustomerFixture sut = new UpdateCustomerFixture() .WithCustomerRepositoryData(existingCustomers); IActionResult response = await sut.UpdateCustomer(updateCustomer); response.Should().BeOfType <OkResult>(); }
public async Task An_Exception_Is_Raised() { string id = Guid.NewGuid().ToString(); const string firstName = nameof(firstName); const string lastName = nameof(lastName); DateTime dateOfBirth = DateTime.UtcNow; var customer = new Api.Customer { DateOfBirth = dateOfBirth, FirstName = firstName, Id = id, LastName = lastName }; var sut = new UpdateCustomerFixture(); Func <Task> test = async() => await sut.UpdateCustomer(customer); await test.Should().ThrowAsync <ResourceNotFoundException>(); }
public async Task A_Success_Response_Is_Returned() { var customer = new Api.Customer { FirstName = "Joe", Id = Guid.NewGuid().ToString(), LastName = "Blogs", DateOfBirth = DateTime.UtcNow }; var expectedResponse = new CreatedAtRouteResult(new { customerId = customer.Id }, customer) { ContentTypes = new MediaTypeCollection { ContentTypes.CustomerVersion1 } }; FakeIdentityGenerator identityGenerator = new FakeIdentityGenerator() .WithGeneratedIdentities(customer.Id); AddCustomerFixture sut = new AddCustomerFixture() .WithIdentityGenerator(identityGenerator); IActionResult response = await sut.AddCustomer(customer); ((ObjectResult)response).Should().BeEquivalentTo(expectedResponse); }
public async Task Customer_Is_Updated_In_The_Datastore() { string id1 = Guid.NewGuid().ToString(); string id2 = Guid.NewGuid().ToString(); const string firstName1 = nameof(firstName1); const string firstName1a = nameof(firstName1a); const string firstName2 = nameof(firstName2); const string lastName1 = nameof(lastName1); const string lastName1a = nameof(lastName1a); const string lastName2 = nameof(lastName2); DateTime dateOfBirth1 = DateTime.UtcNow; DateTime dateOfBirth1a = dateOfBirth1.AddDays(-1); DateTime dateOfBirth2 = dateOfBirth1.AddDays(-2); var existingCustomers = new Entities.Customer[] { new Entities.Customer { DateOfBirth = dateOfBirth1, FirstName = firstName1, Id = id1, LastName = lastName1 }, new Entities.Customer { DateOfBirth = dateOfBirth2, FirstName = firstName2, Id = id2, LastName = lastName2 }, }; var expectedCustomers = new Entities.Customer[] { new Entities.Customer { DateOfBirth = dateOfBirth1a, FirstName = firstName1a, Id = id1, LastName = lastName1a }, new Entities.Customer { DateOfBirth = dateOfBirth2, FirstName = firstName2, Id = id2, LastName = lastName2 }, }; var updateCustomer = new Api.Customer { DateOfBirth = dateOfBirth1a, FirstName = firstName1a, Id = id1, LastName = lastName1a }; UpdateCustomerFixture sut = new UpdateCustomerFixture() .WithCustomerRepositoryData(existingCustomers); await sut.UpdateCustomer(updateCustomer); sut.PostTestCustomers.Should().BeEquivalentTo(expectedCustomers); }