public async Task UpdateProfile_Successfully() { using (var db = new DbTestConnection()) { _CustomerRepo.Setup(s => s.DbSet).Returns(db.Db.Set <Models.Customer>()); _CustomerRepo.Setup(s => s.DbSetTrail).Returns(db.DbTrail.Set <Models.CustomerTrail>()); // prepare data var service = CreateService(db); var newCustomer = await service.NewCustomerAsync("Andy", "Kribo"); DateTimeOffset timeOfCreated = newCustomer.UpdatedAt; _CustomerRepo.Setup(x => x.With(newCustomer.Id)).Returns(newCustomer); // Action var updatedCustomer = await service.UpdateProfileAsync(newCustomer.Id, "Andy", "Hasan"); // Assert : check the time of created not equal the time when updated. updatedCustomer.Id.Should().Be(newCustomer.Id); updatedCustomer.UpdatedAt.Should().BeOnOrAfter(timeOfCreated); // validate the logs, should contain 2 records. (await service.LogsAsync(newCustomer.Id)).Should().HaveCount(2); } }
public async Task CreateCustomer_Fail_FirstName(string firstName, string lastName) { using (var db = new DbTestConnection()) { var service = CreateService(db); // Action Func <Task> act = async() => { await service.NewCustomerAsync(firstName, lastName); }; // Asserts await act.Should().ThrowAsync <ArgumentException>(); } }
public async Task CreateCustomer_Successfully(string firstName, string lastName) { using (var db = new DbTestConnection()) { _CustomerRepo.Setup(s => s.DbSet).Returns(db.Db.Set <Models.Customer>()); // Action var service = CreateService(db); Models.Customer customer = await service.NewCustomerAsync(firstName, lastName);; // Asserts customer.Should().NotBeNull(); customer.FirstName.Should().Be(firstName); customer.LastName.Should().Be(lastName); } }
public async Task Search_Successfully() { using (var db = new DbTestConnection()) { _CustomerRepo.Setup(s => s.DbSet).Returns(db.Db.Set <Models.Customer>()); // prepare data var service = CreateService(db); await service.NewCustomerAsync("Andy", "Hasan"); await service.NewCustomerAsync("Andy", "Kribo"); var customers = await service.SearchAsync(x => x.FirstName == "Andy"); customers.Should().Contain(x => x.FirstName == "Andy"); } }
private MCServiceWebApi.Customers.Service CreateService(DbTestConnection db) { return(new Service(_CustomerRepo.Object, db.Db)); }
private CustomerUseCase CreateService(DbTestConnection db) { return(new CustomerUseCase(_CustomerRepo.Object, db.Db)); }