예제 #1
0
        public void Changing_email_from_corporate_to_non_corporate()
        {
            var optionsBuilder = new DbContextOptionsBuilder <CrmContext>()
                                 .UseSqlServer(ConnectionString);

            using (var context = new CrmContext(optionsBuilder.Options))
            {
                // Arrange
                var userRepository    = new UserRepository(context);
                var companyRepository = new CompanyRepository(context);
                var user = new User(0, "*****@*****.**",
                                    UserType.Employee, false);
                userRepository.SaveUser(user);
                var company = new Company("mycorp.com", 1);
                companyRepository.SaveCompany(company);
                context.SaveChanges();

                var busSpy     = new BusSpy();
                var messageBus = new MessageBus(busSpy);
                var loggerMock = new Mock <IDomainLogger>();
                var sut        = new UserController(
                    context, messageBus, loggerMock.Object);

                // Act
                string result = sut.ChangeEmail(user.UserId, "*****@*****.**");

                // Assert
                Assert.Equal("OK", result);

                User userFromDb = userRepository.GetUserById(user.UserId);
                Assert.Equal("*****@*****.**", userFromDb.Email);
                Assert.Equal(UserType.Customer, userFromDb.Type);

                Company companyFromDb = companyRepository.GetCompany();
                Assert.Equal(0, companyFromDb.NumberOfEmployees);

                busSpy.ShouldSendNumberOfMessages(1)
                .WithEmailChangedMessage(user.UserId, "*****@*****.**");
                loggerMock.Verify(
                    x => x.UserTypeHasChanged(
                        user.UserId, UserType.Employee, UserType.Customer),
                    Times.Once);
            }
        }
예제 #2
0
        public void Changing_email_from_corporate_to_non_corporate()
        {
            // Arrange
            User user = CreateUser("*****@*****.**", UserType.Employee);

            CreateCompany("mycorp.com", 1);

            var busSpy     = new BusSpy();
            var messageBus = new MessageBus(busSpy);
            var loggerMock = new Mock <IDomainLogger>();

            // Act
            string result = Execute(
                x => x.ChangeEmail(user.UserId, "*****@*****.**"),
                messageBus, loggerMock.Object);

            // Assert
            Assert.Equal("OK", result);

            User userFromDb = QueryUser(user.UserId);

            userFromDb
            .ShouldExist()
            .WithEmail("*****@*****.**")
            .WithType(UserType.Customer);
            Company companyFromDb = QueryCompany();

            Assert.Equal(0, companyFromDb.NumberOfEmployees);

            busSpy.ShouldSendNumberOfMessages(1)
            .WithEmailChangedMessage(user.UserId, "*****@*****.**");
            loggerMock.Verify(
                x => x.UserTypeHasChanged(
                    user.UserId, UserType.Employee, UserType.Customer),
                Times.Once);
        }