예제 #1
0
        public void ProjectService_GetAsync_ReturnsProjects()
        {
            //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 dbEntry1 = new Project { Id = "dummyEntryId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = false, ProjectCode = "CODE1" };
            var dbEntry2 = new Project { Id = "dummyEntryId2", ProjectName = "Project2", ProjectAltName = "ProjectAlt2", IsActive_bl = true, ProjectCode = "CODE2" };
            var dbEntries = (new List<Project> { dbEntry1, dbEntry2 }).AsQueryable();

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

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

            //Act
            var resultProjects = projectService.GetAsync().Result;
            
            //Assert
            Assert.IsTrue(resultProjects.Count == 1);
            Assert.IsTrue(resultProjects[0].ProjectAltName.Contains("ProjectAlt2"));
        }
        public void ComponentLogEntryService_GetAsync_ReturnsComponentLogEntrysByIds()
        {
            //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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project { Id = "dummyProjId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new ComponentLogEntry { Id = "dummyEntryId1", Component_Id = "dummyCompId1", AssignedToProject_Id = "dummyProjId1",
                IsActive_bl = false, Comments = "DummyComments1", AssignedToProject = project1 };
            var dbEntry2 = new ComponentLogEntry { Id = "dummyEntryId2", Component_Id = "dummyCompId2", AssignedToProject_Id = "dummyProjId1",
                IsActive_bl = true, Comments = "DummyComments2", AssignedToProject = project1 };
            var dbEntry3 = new ComponentLogEntry { Id = "dummyEntryId3", Component_Id = "dummyCompId3", AssignedToProject_Id = "dummyProjId1",
                IsActive_bl = true, Comments = "DummyComments3", AssignedToProject = project1 };
            var dbEntries = (new List<ComponentLogEntry> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

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

            var compLogEntryService = new ComponentLogEntryService(mockDbContextScopeFac.Object, projectPerson1.Id);

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

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

        }
예제 #3
0
        public void AssemblyDbService_GetAsync_ReturnsAssemblyDbsByIds()
        {
            //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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new AssemblyDb { Id = "dummyEntryId1", AssyName = "Assy1", AssyAltName = "AssyAlt1", IsActive_bl = false, 
                TechnicalDetails = "DummyInfo1" , AssignedToProject = project1 };
            var dbEntry2 = new AssemblyDb { Id = "dummyEntryId2", AssyName = "Assy2", AssyAltName = "AssyAlt2", IsActive_bl = true,
                TechnicalDetails = "DummyInfo2" , AssignedToProject = project1 };
            var dbEntry3 = new AssemblyDb { Id = "dummyEntryId3", AssyName = "Assy3", AssyAltName = "AssyAlt3", IsActive_bl = true, 
                TechnicalDetails = "DummyInfo3" , AssignedToProject = project1 };
            var dbEntries = (new List<AssemblyDb> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

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

            var assemblyService = new AssemblyDbService(mockDbContextScopeFac.Object, projectPerson1.Id);

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

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

        }
예제 #4
0
        public void ProjectEventService_GetAsync_DoeNotReturnProjectEventsFromWrongProject()
        {
            //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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };
            var projectPerson2 = new Person { Id = "dummyUserId2", FirstName = "Firs2", LastName = "Last2" };

            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };
            var project2 = new Project { Id = "dummyId2", ProjectName = "Project2", ProjectAltName = "ProjectAlt2", IsActive_bl = false, ProjectCode = "CODE2", 
                ProjectPersons = new List<Person> { projectPerson2 } };

            var dbEntry1 = new ProjectEvent { Id = "dummyEntryId1", EventName = "Event1", EventAltName = "EventAlt1", IsActive_bl = false, Comments = "DummyComments1",
                 AssignedToProject = project1 };
            var dbEntry2 = new ProjectEvent { Id = "dummyEntryId2", EventName = "Event2", EventAltName = "EventAlt2", IsActive_bl = true, Comments = "DummyComments2",
                 AssignedToProject = project2 };
            var dbEntries = (new List<ProjectEvent> { dbEntry1, dbEntry2 }).AsQueryable();

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

            var eventService = new ProjectEventService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var resultProjectEvents = eventService.GetAsync().Result;
            
            //Assert
            Assert.IsTrue(resultProjectEvents.Count == 0);
        }
예제 #5
0
        public void LocationService_GetAsync_ReturnsLocations()
        {
            //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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new Location { Id = "dummyEntryId1", LocName = "Loc1", LocAltName = "LocAlt1", IsActive_bl = false, Comments = "DummyComments1",
                AccessInfo = "DummyInfo1", AssignedToProject = project1 };
            var dbEntry2 = new Location { Id = "dummyEntryId2", LocName = "Loc2", LocAltName = "LocAlt2", IsActive_bl = true, Comments = "DummyComments2",
                AccessInfo = "DummyInfo2", AssignedToProject = project1 };
            var dbEntries = (new List<Location> { dbEntry1, dbEntry2 }).AsQueryable();

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

            var locationService = new LocationService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var resultLocations = locationService.GetAsync(new[] {dbEntry1.Id, dbEntry2.Id}).Result;
            
            //Assert
            Assert.IsTrue(resultLocations.Count == 1);
            Assert.IsTrue(resultLocations[0].LocAltName.Contains("LocAlt2"));
        }
예제 #6
0
 public async Task<ActionResult> Edit(Project[] records)
 {
     ViewBag.ServiceName = "ProjectService.EditAsync";
     var newEntryIds = await projectService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True", newEntryIds = newEntryIds });
 }
예제 #7
0
        public void PersonLogEntryService_GetAsync_DoesNotReturnPersonLogEntrysByIdsIfNotActive()
        {
            //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 userId = "DummyUserId";

            var projectPerson1 = new Person { Id = userId, FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project
            {
                Id = "dummyId1",
                ProjectName = "Project1",
                ProjectAltName = "ProjectAlt1",
                IsActive_bl = true,
                ProjectCode = "CODE1",
                ProjectPersons = new List<Person> { projectPerson1 }
            };

            var dbEntry1 = new PersonLogEntry { Id = "dummyEntryId1", LogEntryDateTime = new DateTime(2000, 1, 1), IsActive_bl = false, AssignedToProject = project1 };
            var dbEntry2 = new PersonLogEntry { Id = "dummyEntryId2", LogEntryDateTime = new DateTime(2000, 1, 2), IsActive_bl = true, AssignedToProject = project1 };
            var dbEntry3 = new PersonLogEntry { Id = "dummyEntryId3", LogEntryDateTime = new DateTime(2000, 1, 3), IsActive_bl = false, AssignedToProject = project1 };
            var dbEntries = (new List<PersonLogEntry> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

            //var userRole1 = new IdentityRole { Id = "dummyRoleId1", Name = "YourActivity_View", };
            //var userRole2 = new IdentityRole { Id = "dummyRoleId2", Name = "PersonLogEntry_View" };

            //var userRoles = new List<IdentityRole> { userRole1, userRole2 }.AsQueryable();

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

            //mockEfDbContext.Setup(x => x.Roles).Returns(mockDbSetRoles.Object);

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

            var prsLogEntryService = new PersonLogEntryService(mockDbContextScopeFac.Object, userId);

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

            //Assert
            Assert.IsTrue(serviceResult.Count == 0);
        }
예제 #8
0
        public void BaseDbService_GetActivitySummariesAsync_ReturnsProperGroups()
        {
            // 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 personId = "DummyUserId";
            var startDate = new DateTime(2000,1,1);
            var endDate = new DateTime(2000,1,3);

            var person = new Person { Id = personId };

            var project1 = new Project {Id = "ProjectId1", ProjectName = "ProjectName1", ProjectCode = "ProjectCode1" };
            var project2 = new Project { Id = "ProjectId2", ProjectName = "ProjectName2", ProjectCode = "ProjectCode2" };

            var dbEntry1 = new PersonLogEntry { Id = "Id1", LogEntryDateTime = new DateTime(2000, 1, 1, 10, 0, 0), IsActive_bl = true, EnteredByPerson_Id = "otherPersonId",
                                                AssignedToProject_Id = "ProjectId1", AssignedToProject = project1, ManHours = 3, PrsLogEntryPersons = new List<Person> {person}};
            var dbEntry2 = new PersonLogEntry { Id = "Id2", LogEntryDateTime = new DateTime(2000, 1, 1, 11, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId2", AssignedToProject = project2, ManHours = 4};
            var dbEntry3 = new PersonLogEntry { Id = "Id3", LogEntryDateTime = new DateTime(2000, 1, 1, 12, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId1", AssignedToProject = project1, ManHours = 5};
            var dbEntry4 = new PersonLogEntry { Id = "Id4", LogEntryDateTime = new DateTime(2000, 1, 1, 13, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId2", AssignedToProject = project2, ManHours = 6};
            
            var dbEntry5 = new PersonLogEntry { Id = "Id5", LogEntryDateTime = new DateTime(2000, 1, 2, 10, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId1", AssignedToProject = project1, ManHours = 7};
            var dbEntry6 = new PersonLogEntry { Id = "Id6", LogEntryDateTime = new DateTime(2000, 1, 2, 11, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId2", AssignedToProject = project2, ManHours = 8 };

            var dbEntry7 = new PersonLogEntry { Id = "Id7", LogEntryDateTime = new DateTime(2000, 1, 1, 9, 0, 0), IsActive_bl = true, EnteredByPerson_Id = "otherPersonId",
                                                AssignedToProject_Id = "ProjectId2", AssignedToProject = project2, ManHours = 100 };
            var dbEntry8 = new PersonLogEntry { Id = "Id8", LogEntryDateTime = new DateTime(2000, 1, 4, 10, 0, 0), IsActive_bl = true, EnteredByPerson_Id = personId,
                                                AssignedToProject_Id = "ProjectId1", AssignedToProject = project1, ManHours = 1000 };

            var dbEntrys = new PersonLogEntry[] { dbEntry1, dbEntry2, dbEntry3, dbEntry4, dbEntry5, dbEntry6, dbEntry7, dbEntry8 }.AsQueryable();

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

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

            var personLogEntryService = new PersonLogEntryService(mockDbContextScopeFac.Object, personId);

            //Act
            var serviceResult = personLogEntryService.GetActivitySummariesAsync(personId, startDate, endDate).Result;

            //Assert
            Assert.IsTrue(serviceResult.Count == 2);
            Assert.IsTrue(serviceResult[0].TotalManHours == dbEntry1.ManHours + dbEntry2.ManHours + dbEntry3.ManHours + dbEntry4.ManHours);
            Assert.IsTrue(serviceResult[0].SummaryDay == dbEntry4.LogEntryDateTime.Date);
            Assert.IsTrue(serviceResult[1].SummaryDetails.Count() == 2);
            Assert.IsTrue(serviceResult[1].TotalManHours == dbEntry5.ManHours + dbEntry6.ManHours);
            Assert.IsTrue(serviceResult.All(x => x.PersonId == personId));

        }
예제 #9
0
        public void ComponentService_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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new Component { Id = "dummyEntryId1", CompName = "Comp1", CompAltName = "CompAlt1", CompAltName2 = "CompAlt1", IsActive_bl = true, 
                ProgramAddress = "DummyInfo1" , AssignedToProject = project1 };
            var dbEntry2 = new Component { Id = "dummyEntryId2", CompName = "Comp2", CompAltName = "CompAlt2", CompAltName2 = "CompAlt2", IsActive_bl = true,
                ProgramAddress = "DummyInfo2" , AssignedToProject = project1 };
            var dbEntry3 = new Component { Id = "dummyEntryId3", CompName = "Comp3", CompAltName = "CompAlt3", CompAltName2 = "CompAlt3", IsActive_bl = false, 
                ProgramAddress = "DummyInfo3" , AssignedToProject = project1 };
            var dbEntries = (new List<Component> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

            var componentService = new ComponentService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var returnedComps = componentService.LookupAsync("Comp3", true).Result;

            //Assert
            Assert.IsTrue(returnedComps.Count == 0);
        }
예제 #10
0
        public void ProjectService_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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var dbEntry1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };
            var dbEntry2 = new Project { Id = "dummyId2", ProjectName = "Project2", ProjectAltName = "ProjectAlt2", IsActive_bl = false, ProjectCode = "CODE2", 
                ProjectPersons = new List<Person> { projectPerson1 } };
            var dbEntry3 = new Project { Id = "dummyId3", ProjectName = "Project3", ProjectAltName = "ProjectAlt3", IsActive_bl = true, ProjectCode = "CODE3", 
                ProjectPersons = new List<Person> { projectPerson1 } };

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

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

            var projectService = new ProjectService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var returnedProjects = projectService.LookupAsync("CODE2", true).Result;

            //Assert
            Assert.IsTrue(returnedProjects.Count == 0);
        }
예제 #11
0
        public void AssemblyDbService_EditStatusAsync_EditsStatusIfDifferent()
        {
            // Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextScope>();
            var mockDbContextScopeReadOnly = new Mock<IDbContextReadOnlyScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.Create(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScopeReadOnly.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);
            mockDbContextScopeReadOnly.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var ids = new[] { "dummyEntryId1", "dummyEntryId2"};
            var statusId = "newStatusId";

            var userId = "dummyUserId1";
            var projectPerson1 = new Person { Id = userId, FirstName = "Firs1", LastName = "Last1" };
            
            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new AssemblyDb { Id = "dummyEntryId1", AssyName = "Assy1", AssyAltName = "AssyAlt1", IsActive_bl = true, 
                TechnicalDetails = "DummyInfo1" , AssignedToProject = project1 };
            var dbEntry2 = new AssemblyDb { Id = "dummyEntryId2", AssyName = "Assy2", AssyAltName = "AssyAlt2", IsActive_bl = true,
                TechnicalDetails = "DummyInfo2" , AssignedToProject = project1, AssemblyStatus_Id = statusId };
            var dbEntry3 = new AssemblyDb { Id = "dummyEntryId3", AssyName = "Assy3", AssyAltName = "AssyAlt3", IsActive_bl = true, 
                TechnicalDetails = "DummyInfo3" , AssignedToProject = project1 };
            var dbEntries = (new List<AssemblyDb> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();
            
            var mockDbSet = new Mock<DbSet<AssemblyDb>>();
            mockDbSet.As<IDbAsyncEnumerable<AssemblyDb>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<AssemblyDb>(() => dbEntries.GetEnumerator()));
            mockDbSet.As<IQueryable<AssemblyDb>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<AssemblyDb>(dbEntries.Provider));
            mockDbSet.As<IQueryable<AssemblyDb>>().Setup(m => m.Expression).Returns(dbEntries.Expression);
            mockDbSet.As<IQueryable<AssemblyDb>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType);
            mockDbSet.As<IQueryable<AssemblyDb>>().Setup(m => m.GetEnumerator()).Returns(() => dbEntries.GetEnumerator());
            mockDbSet.Setup(x => x.Include(It.IsAny<string>())).Returns(mockDbSet.Object);
            mockDbSet.Setup(x => x.FindAsync(dbEntry1.Id)).Returns(Task.FromResult(dbEntry1));
            mockDbSet.Setup(x => x.FindAsync(dbEntry2.Id)).Returns(Task.FromResult(dbEntry2));

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

            var logEntry = new AssemblyLogEntry();

            mockEfDbContext.Setup(x => x.Set<AssemblyDb>().FindAsync(dbEntry1.Id)).Returns(Task.FromResult(dbEntry1));
            mockEfDbContext.Setup(x => x.Set<AssemblyDb>().FindAsync(dbEntry2.Id)).Returns(Task.FromResult(dbEntry1));

            mockEfDbContext.Setup(x => x.AssemblyLogEntrys.Add(It.IsAny<AssemblyLogEntry>())).Callback<AssemblyLogEntry>( x => logEntry = x);
            mockEfDbContext.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult<int>(1));

            var assemblyService = new AssemblyDbService(mockDbContextScopeFac.Object, userId);

            //Act
            assemblyService.EditStatusAsync(ids,statusId).Wait();

            //Assert
            Assert.IsTrue(dbEntry1.AssemblyStatus_Id == statusId);
            Assert.IsTrue(dbEntry2.AssemblyStatus_Id == statusId);
            Assert.IsTrue(logEntry.AssignedToLocation_Id == dbEntry2.AssignedToLocation_Id);
            mockDbContextScopeFac.Verify(x => x.Create(DbContextScopeOption.JoinExisting), Times.Once);
            mockDbContextScope.Verify(x => x.DbContexts.Get<EFDbContext>(), Times.Once);
            mockEfDbContext.Verify(x => x.AssemblyLogEntrys.Add(It.IsAny<AssemblyLogEntry>()), Times.Once);
            mockEfDbContext.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
예제 #12
0
        public void DocumentService_LookupAsync_ReturnsMatchingRecords()
        {
            // 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 projectPerson1 = new Person { Id = "dummyUserId1", FirstName = "Firs1", LastName = "Last1" };

            var project1 = new Project { Id = "dummyId1", ProjectName = "Project1", ProjectAltName = "ProjectAlt1", IsActive_bl = true, ProjectCode = "CODE1", 
                ProjectPersons = new List<Person> { projectPerson1 } };

            var dbEntry1 = new Document { Id = "dummyEntryId1", DocName = "Doc1", DocAltName = "DocAlt1", IsActive_bl = true, 
                DocFilePath = "DummyPath1" , AssignedToProject = project1 };
            var dbEntry2 = new Document { Id = "dummyEntryId2", DocName = "Doc2", DocAltName = "DocAlt2", IsActive_bl = true,
                DocFilePath = "DummyPath2" , AssignedToProject = project1 };
            var dbEntry3 = new Document { Id = "dummyEntryId3", DocName = "Doc3", DocAltName = "DocAlt3", IsActive_bl = false, 
                DocFilePath = "DummyPath3" , AssignedToProject = project1 };
            var dbEntries = (new List<Document> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

            var docService = new DocumentService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var returnedDocs = docService.LookupAsync("Doc1", true).Result;

            //Assert
            Assert.IsTrue(returnedDocs.Count == 1);
            Assert.IsTrue(returnedDocs[0].DocAltName.Contains("DocAlt1"));
        }