Ejemplo n.º 1
0
        public async void Add_CustomerRepositorySucceeds_ExpectedCallsWereMade()
        {
            // Arrange
            var customerToAdd = CreateRandomCustomer();

            var customerRepositoryMock = new CustomerRepositoryMock();

            customerRepositoryMock.SetupAddReturns(customerToAdd);

            var customerService = CreateCustomerService(customerRepositoryMock);

            // Act
            await customerService.Add(customerToAdd);

            // Assert
            customerRepositoryMock.VerifyOnlyAddWasCalledOnce(customerToAdd);
        }
Ejemplo n.º 2
0
        public async void Add_CustomerRepositoryReturnsNull_ThrowsExceptionAndExpectedCallsWereMade()
        {
            // Arrange
            Customer     customerToAdd            = null;
            const string expectedExceptionMessage = "An error occurred when trying to add the customer.";

            var customerRepositoryMock = new CustomerRepositoryMock();

            customerRepositoryMock.SetupAddReturns(customerToAdd);

            var customerService = CreateCustomerService(customerRepositoryMock);

            // Act
            var exception = await Record.ExceptionAsync(() => customerService.Add(customerToAdd));

            // Assert
            VerifyException <Exception>(exception, expectedExceptionMessage);
            customerRepositoryMock.VerifyOnlyAddWasCalledOnce(customerToAdd);
        }