Beispiel #1
0
        public void GetByManagerIdGenericShouldMapCorrectlyUsingMoq()
        {
            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);

            var repository = new Mock <IDeletableEntityRepository <Partner> >();

            var manager = new ApplicationUser {
                Email = "TestEmail", Id = "TestManagerId"
            };
            var partners = new List <Partner>
            {
                new Partner {
                    Id = 1, IsApproved = false, IsDeleted = true, DeletedOn = DateTime.UtcNow, Manager = manager, ManagerId = manager.Id, CompanyName = "TestCompany", CompanyUrl = "TestUrl"
                },
                new Partner {
                    Id = 2, IsApproved = true, Manager = manager
                },
            };

            repository.Setup(r => r.AllAsNoTracking()).Returns(partners.AsQueryable());

            var service = new PartnersService(repository.Object, null, null);

            Assert.Equal(1, service.GetByManagerId <PartnerViewModel>("TestManagerId").Id);
            Assert.Equal("TestCompany", service.GetByManagerId <PartnerViewModel>("TestManagerId").CompanyName);
            Assert.Equal("TestUrl", service.GetByManagerId <PartnerViewModel>("TestManagerId").CompanyUrl);
            Assert.Equal("TestEmail", service.GetByManagerId <PartnerViewModel>("TestManagerId").ManagerEmail);

            repository.Verify(x => x.AllAsNoTracking(), Times.Exactly(4));
        }