コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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>();
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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");
            }
        }
コード例 #5
0
 private MCServiceWebApi.Customers.Service CreateService(DbTestConnection db)
 {
     return(new Service(_CustomerRepo.Object, db.Db));
 }
コード例 #6
0
 private CustomerUseCase CreateService(DbTestConnection db)
 {
     return(new CustomerUseCase(_CustomerRepo.Object, db.Db));
 }