コード例 #1
0
            public void a_full_name_should_be_created_from_first_and_last_name()
            {
                //Arrange
                var customerToCreateDto = new CustomerToCreateDto
                                              {
                                                  FirstName = "Bob",
                                                  LastName = "Builder"
                                              };

                var mockCustomerRepository = new Mock<ICustomerRepository>();
                var mockFullNameBuilder = new Mock<ICustomerFullNameBuilder>();

                mockFullNameBuilder.Setup(
                    x => x.From(It.IsAny<string>(), It.IsAny<string>()));

                var customerService = new CustomerService(
                    mockCustomerRepository.Object, mockFullNameBuilder.Object);

                //Act
                customerService.Create(customerToCreateDto);

                //Assert
                mockFullNameBuilder.Verify(x=>x.From(
                    It.Is<string>(
                        fn=>fn.Equals(customerToCreateDto.FirstName,
                            StringComparison.InvariantCultureIgnoreCase)),
                    It.Is<string>(
                        fn=>fn.Equals(customerToCreateDto.LastName,
                            StringComparison.InvariantCultureIgnoreCase))));
            }
コード例 #2
0
            public void a_full_name_should_be_created_from_first_and_last_name()
            {
                //Arrange
                var customerToCreateDto = new CustomerToCreateDto
                                              {
                                                  FirstName = "Bob",
                                                  LastName = "Builder"
                                              };

                var mockCustomerRepository = new Mock<ICustomerRepository>();
                var mockFullNameBuilder = new Mock<ICustomerFullNameBuilder>();

                mockFullNameBuilder.Setup(
                    x => x.From(It.IsAny<string>(), It.IsAny<string>()));

                var customerService = new CustomerService(
                    mockCustomerRepository.Object, mockFullNameBuilder.Object);

                //Act
                customerService.Create(customerToCreateDto);

                //Assert
                mockFullNameBuilder.Verify(x => x.From("Bob", "Builder"));
            }