Пример #1
0
        public void EditAddressShould_CallUnitOfWorkMethodCommit_WhenAddressWasFound(string country, string city, string area, string street, int number)
        {
            var repositoryMock = new Mock <IRepository <Address> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IAddressFactory>();

            var id      = Guid.NewGuid();
            var address = new Address()
            {
                Id      = id,
                Country = country,
                City    = city,
                Street  = street,
                Area    = area,
                Number  = number
            };

            repositoryMock.Setup(r => r.GetById(id)).Returns(address);

            var service = new Services.AddressService(repositoryMock.Object,
                                                      unitOfWorkMock.Object, factoryMock.Object);

            service.EditAddress(id, country, city, area, street, number);

            unitOfWorkMock.Verify(r => r.Commit(), Times.Once);
        }
Пример #2
0
        public void EditAddressShould_ReturnAddress_WhenAddressWasFound(string country, string city, string area, string street, int number)
        {
            var repositoryMock = new Mock <IRepository <Address> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IAddressFactory>();

            var id      = Guid.NewGuid();
            var address = new Address()
            {
                Id      = id,
                Country = country,
                City    = city,
                Street  = street,
                Area    = area,
                Number  = number
            };

            repositoryMock.Setup(r => r.GetById(id)).Returns(address);

            var service = new Services.AddressService(repositoryMock.Object,
                                                      unitOfWorkMock.Object, factoryMock.Object);

            var result = service.EditAddress(id, country, city, area, street, number);

            Assert.AreSame(address, result);
        }
Пример #3
0
        public void EditAddressShould_CallRepositoryMethodGetById(string country, string city, string area, string street, int number)
        {
            var repositoryMock = new Mock <IRepository <Address> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IAddressFactory>();

            var id = Guid.NewGuid();

            var service = new Services.AddressService(repositoryMock.Object,
                                                      unitOfWorkMock.Object, factoryMock.Object);

            service.EditAddress(id, country, city, area, street, number);

            repositoryMock.Verify(r => r.GetById(id), Times.Once);
        }
Пример #4
0
        public void EditAddressShould_ReturnNull_WhenAddressWasNotFound(string country, string city, string area, string street, int number)
        {
            var repositoryMock = new Mock <IRepository <Address> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IAddressFactory>();

            var id = Guid.NewGuid();

            repositoryMock.Setup(r => r.GetById(id)).Returns((Address)null);

            var service = new Services.AddressService(repositoryMock.Object,
                                                      unitOfWorkMock.Object, factoryMock.Object);

            var result = service.EditAddress(id, country, city, area, street, number);

            Assert.IsNull(result);
        }