Пример #1
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);
        }
Пример #2
0
 public async Task<ActionResult> Edit(ProjectEvent[] records)
 {
     ViewBag.ServiceName = "ProjectEventService.EditAsync";
     var newEntryIds = await projectEventService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True", newEntryIds = newEntryIds });
 }
Пример #3
0
        public void BaseDbService_EditAsync_DoesNotUpdateIfProjLocIdsNotMatching()
        {
            // Arrange
            var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>();
            var mockDbContextScope = new Mock<IDbContextScope>();
            var mockEfDbContext = new Mock<EFDbContext>();
            mockDbContextScopeFac.Setup(x => x.Create(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object);
            mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object);

            var userId = "DummyUserId";

            var record1 = new PersonLogEntry
            {
                Id = "dummyRecordId1",
                LogEntryDateTime = new DateTime(2000, 1, 1),
                IsActive_bl = false,
                AssignedToProject_Id = "DummyProjectId",
                AssignedToProjectEvent_Id = "DummyProjEntryID",
                ModifiedProperties = new[] { "LogEntryDateTime" }
            };
            var record2 = new PersonLogEntry
            {
                Id = "dummyRecordId2",
                LogEntryDateTime = new DateTime(2000, 1, 2),
                IsActive_bl = true,
                AssignedToProject_Id = "DummyProjectId",
                AssignedToProjectEvent_Id = "DummyProjEntryID",
                AssignedToLocation_Id = "DummyLocId",
                ModifiedProperties = new[] { "LogEntryDateTime", "AssignedToProjectEvent_Id", "AssignedToLocation_Id" }
            };
            var records = new PersonLogEntry[] { record1, record2 };

            var projEventDbEntry = new ProjectEvent { Id = "DummyProjEntryID", AssignedToProject_Id = "DummyProjectId" };

            var locDbEntry = new Location { Id = "DummyLocId", AssignedToProject_Id = "DummyProjectId2" };

            var dbEntry1 = new PersonLogEntry { Id = "dummyEntryId1", LogEntryDateTime = new DateTime(2001, 1, 1), IsActive_bl = true };
            var dbEntry2 = new PersonLogEntry { Id = "dummyEntryId2", LogEntryDateTime = new DateTime(2001, 1, 2), IsActive_bl = false };

            mockEfDbContext.Setup(x => x.PersonLogEntrys.FindAsync(record1.Id)).Returns(Task.FromResult(dbEntry1));
            mockEfDbContext.Setup(x => x.PersonLogEntrys.FindAsync(record2.Id)).Returns(Task.FromResult(dbEntry2));
            mockEfDbContext.Setup(x => x.ProjectEvents.FindAsync(projEventDbEntry.Id)).Returns(Task.FromResult<ProjectEvent>(projEventDbEntry));
            mockEfDbContext.Setup(x => x.ProjectEvents.FindAsync(It.IsNotIn<string>(new[] { projEventDbEntry.Id }))).Returns(Task.FromResult<ProjectEvent>(null));
            mockEfDbContext.Setup(x => x.Locations.FindAsync(locDbEntry.Id)).Returns(Task.FromResult<Location>(locDbEntry));
            mockEfDbContext.Setup(x => x.PersonLogEntrys.Add(record1)).Verifiable();
            mockEfDbContext.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult<int>(1));

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

            //Act
            var serviceResult = personLogEntryService.EditAsync(records).Result;

            //Assert
        }