Ejemplo n.º 1
0
        public void PersonGroupService_GetAsync_ReturnsPersonGroupsByIds()
        {
            //Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextReadOnlyScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var mockAppUserManager = new Mock<IAppUserManager>();
            var mockDbUserService = new Mock<DBUserService>(new object[] {mockDbContextScopeFac.Object, mockAppUserManager.Object,  true });
            var mockPersonService = new Mock<PersonService>(new object[] { mockDbContextScopeFac.Object, mockDbUserService.Object });

            var dbEntry1 = new PersonGroup { Id = "dummyEntryId1", PrsGroupName = "PersonGroup1", PrsGroupAltName = "PersonGroupAlt1", IsActive_bl = false };
            var dbEntry2 = new PersonGroup { Id = "dummyEntryId2", PrsGroupName = "PersonGroup2", PrsGroupAltName = "PersonGroupAlt2", IsActive_bl = true };
            var dbEntry3 = new PersonGroup { Id = "dummyEntryId3", PrsGroupName = "PersonGroup3", PrsGroupAltName = "PersonGroupAlt3", IsActive_bl = true };
            var dbEntries = (new List<PersonGroup> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<PersonGroup>>();
            mockDbSet.As<IDbAsyncEnumerable<PersonGroup>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<PersonGroup>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<PersonGroup>(dbEntries.Provider));
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);

            mockEfDbContext.Setup(x => x.PersonGroups).Returns(mockDbSet.Object);

            var PersonGroupService = new PersonGroupService(mockDbContextScopeFac.Object, "dummyUserId");

            //Act
            var serviceResult = PersonGroupService.GetAsync(new string[] { "dummyEntryId3" }).Result;

            //Assert
            Assert.IsTrue(serviceResult.Count == 1);
            Assert.IsTrue(serviceResult[0].PrsGroupAltName.Contains("PersonGroupAlt3"));

        }
Ejemplo n.º 2
0
        public void PersonService_LookupAsync_ReturnsNoPersons()
        {
            //Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextReadOnlyScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var groupManager1 = new Person { Id = "dummyUserId1", FirstName = "FirstManager1", LastName = "LastManager1" };
            var groupManager2 = new Person { Id = "dummyUserId2", FirstName = "FirstManager2", LastName = "LastManager2" };

            var personGroupDbEntry1 = new PersonGroup { GroupManagers = new List<Person> { groupManager1 }, };
            var personGroupDbEntry2 = new PersonGroup { GroupManagers = new List<Person> { groupManager2 }, };

            var dbEntry1 = new Person { Id = "dummyEntryId1", FirstName = "First1", LastName = "Last1", IsActive_bl = false, Initials = "FLA1",
                                        PersonGroups = new List<PersonGroup> {personGroupDbEntry1}};
            var dbEntry2 = new Person { Id = "dummyEntryId2", FirstName = "First2", LastName = "Last2", IsActive_bl = true, Initials = "FLA2",
                                        PersonGroups = new List<PersonGroup> {personGroupDbEntry1}};
            var dbEntry3 = new Person { Id = "dummyEntryId3", FirstName = "First3", LastName = "Last3", IsActive_bl = true, Initials = "FLA3",
                                        PersonGroups = new List<PersonGroup> { personGroupDbEntry1 }};
            var dbEntry4 = new Person { Id = "dummyEntryId4", FirstName = "First4", LastName = "Last4", IsActive_bl = true, Initials = "FLA4",
                                        PersonGroups = new List<PersonGroup> { personGroupDbEntry2 }};

            var personDbEntries = (new List<Person> { dbEntry1, dbEntry2, dbEntry3, dbEntry4 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<Person>>();
            mockDbSet.As<IDbAsyncEnumerable<Person>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<Person>(personDbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<Person>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<Person>(personDbEntries.Provider));
            mockDbSet.As<IQueryable<Person>>().Setup(m => m.Expression).Returns(personDbEntries.Expression);
            mockDbSet.As<IQueryable<Person>>().Setup(m => m.ElementType).Returns(personDbEntries.ElementType);
            mockDbSet.As<IQueryable<Person>>().Setup(m => m.GetEnumerator()).Returns(personDbEntries.GetEnumerator());

            mockEfDbContext.Setup(x => x.Persons).Returns(mockDbSet.Object);

            var personService = new PersonService(mockDbContextScopeFac.Object, groupManager1.Id);

            //Act
            var returnedProjects = personService.LookupAsync("FLA1").Result;

            //Assert
            Assert.IsTrue(returnedProjects.Count == 0);
        }
Ejemplo n.º 3
0
        public void PersonGroupService_LookupAsync_ReturnsNoRecordsIfNotActive()
        {
            // Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextReadOnlyScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var mockAppUserManager = new Mock<IAppUserManager>();
            var mockDbUserService = new Mock<DBUserService>(new object[] {mockDbContextScopeFac.Object, mockAppUserManager.Object,  true });
            var mockPersonService = new Mock<PersonService>(new object[] { mockDbContextScopeFac.Object, mockDbUserService.Object });

            var groupManager1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var dbEntry1 = new PersonGroup { Id = "dummyId1", PrsGroupName = "PersonGroup1", PrsGroupAltName = "PersonGroupAlt1", IsActive_bl = true,
                GroupManagers = new List<Person>{groupManager1} };
            var dbEntry2 = new PersonGroup { Id = "dummyId2", PrsGroupName = "PersonGroup2", PrsGroupAltName = "PersonGroupAlt2", IsActive_bl = false,
                GroupManagers = new List<Person>{groupManager1} };
            var dbEntry3 = new PersonGroup { Id = "dummyId3", PrsGroupName = "PersonGroup3", PrsGroupAltName = "PersonGroupAlt3", IsActive_bl = true,
                GroupManagers = new List<Person>{groupManager1} };

            var dbEntries = (new List<PersonGroup> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

            var mockDbSet = new Mock<DbSet<PersonGroup>>();
            mockDbSet.As<IDbAsyncEnumerable<PersonGroup>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<PersonGroup>(dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<PersonGroup>(dbEntries.Provider));
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<PersonGroup>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator());
            mockEfDbContext.Setup(x => x.PersonGroups).Returns(mockDbSet.Object);

            var PersonGroupService = new PersonGroupService(mockDbContextScopeFac.Object, groupManager1.Id);

            //Act
            var returnedPersonGroups = PersonGroupService.LookupAsync("website2", true).Result;

            //Assert
            Assert.IsTrue(returnedPersonGroups.Count == 0);
        }
Ejemplo n.º 4
0
 public async Task<ActionResult> Edit(PersonGroup[] records)
 {
     ViewBag.ServiceName = "PersonGroupService.EditAsync";
     var newEntryIds = await personGroupService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True", newEntryIds = newEntryIds });
 }