Exemplo n.º 1
0
        public async void DeleteTest()
        {
            // Arrange
            var mockLogManager        = new Mock <ILogManager>();
            var mockAddressRepository = new Mock <IAddressRepository>();
            var mockAddress           = new Mock <IAddress>();
            var mockAddressValidator  = new Mock <IAddressValidator>();

            // Setup mock methods/properties
            mockAddress.Setup(c => c.Id).Returns(It.IsAny <int>());
            mockAddressRepository.Setup(x => x.DeleteAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(new DeleteResponse {
                Message = "Successful."
            }));

            // Act
            var sut = new AddressApplicationService(
                mockLogManager.Object, mockAddressRepository.Object, mockAddressValidator.Object);
            var response = await sut.DeleteAsync(It.IsAny <int>());

            // Assert
            response.IsSuccessful.Should().BeTrue();
            response.Errors.Count.Should().Be(0);
            response.Message.Should().NotBeNullOrEmpty();

            // Verify the application service is calling the correct repository method.
            mockAddressRepository.Verify(x => x.DeleteAsync(It.IsAny <int>()));
        }
Exemplo n.º 2
0
        public async void DeleteErrorTest()
        {
            // Arrange
            var mockLogManager        = new Mock <ILogManager>();
            var mockAddressRepository = new Mock <IAddressRepository>();
            var mockAddress           = new Mock <IAddress>();
            var mockAddressValidator  = new Mock <IAddressValidator>();

            // Setup mock methods/properties
            mockAddress.Setup(c => c.Id).Returns(It.IsAny <int>());
            mockAddressRepository.Setup(x => x.DeleteAsync(It.IsAny <int>()))
            .Throws(new Exception());

            // Act
            var sut = new AddressApplicationService(
                mockLogManager.Object, mockAddressRepository.Object, mockAddressValidator.Object);
            var response = await sut.DeleteAsync(It.IsAny <int>());

            // Assert
            response.IsSuccessful.Should().BeFalse();
            response.Errors.Count.Should().BeGreaterThan(0);
            response.Message.Should().NotBeNullOrEmpty();

            // Verify the application service is calling the correct repository method.
            mockAddressRepository.Verify(x => x.DeleteAsync(It.IsAny <int>()));

            // Verify the application service is logging the error.
            mockLogManager.Verify(x => x.LogError(It.IsAny <Exception>(), It.IsAny <string>()));
        }
Exemplo n.º 3
0
        public async void SaveAllTest()
        {
            // Arrange
            var mockLogManager        = new Mock <ILogManager>();
            var mockAddressRepository = new Mock <IAddressRepository>();
            var mockAddresses         = new List <IAddress> {
                new Mock <IAddress>().Object
            };
            var mockAddressValidator = new Mock <IAddressValidator>();

            // Setup mock methods/properties
            mockAddressRepository.Setup(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAddress> >()))
            .Returns(Task.FromResult(new SaveResponse <IReadOnlyList <IAddress> > {
                Message = "Successful."
            }));
            mockAddressValidator.Setup(x => x.ValidateAsync(It.IsNotNull <IAddress>(), CancellationToken.None))
            .Returns(Task.FromResult(new ValidationResult()));

            // Act
            var sut = new AddressApplicationService(
                mockLogManager.Object, mockAddressRepository.Object, mockAddressValidator.Object);
            var response = await sut.SaveAllAsync(mockAddresses);

            // Assert
            response.IsSuccessful.Should().BeTrue();
            response.Errors.Count.Should().Be(0);
            response.Message.Should().NotBeNullOrEmpty();

            // Verify the application service is calling the correct repository method.
            mockAddressRepository.Verify(x => x.SaveAllAsync(It.IsAny <IReadOnlyList <IAddress> >()));

            // Verify the application service is calling the validator
            mockAddressValidator.Verify(x => x.ValidateAsync(It.IsNotNull <IAddress>(), CancellationToken.None));
        }
Exemplo n.º 4
0
        public async void CreateTest()
        {
            // Arrange
            var mockLogManager        = new Mock <ILogManager>();
            var mockAddressRepository = new Mock <IAddressRepository>();
            var mockAddressValidator  = new Mock <IAddressValidator>();

            // Act
            var sut = new AddressApplicationService(
                mockLogManager.Object, mockAddressRepository.Object, mockAddressValidator.Object);
            var response = await sut.CreateAsync();

            // Assert
            response.Content.Should().NotBeNull();
            response.Content.Id.Should().NotBe(0);
        }
 public AddressCommandsController(AddressApplicationService application)
 {
     Application = application;
 }