Exemplo n.º 1
0
        public void AssemblyLogEntryService_GetAsync_DoeNotReturnFromWrongProject()
        {
            //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 AssemblyLogEntry
            {
                Id = "dummyEntryId1",
                AssemblyDb_Id = "dummyAssyId1",
                AssignedToProject_Id = "dummyProjId1",
                IsActive_bl = false,
                Comments = "DummyComments1",
                AssignedToProject = project1
            };
            var dbEntry2 = new AssemblyLogEntry
            {
                Id = "dummyEntryId2",
                AssemblyDb_Id = "dummyAssyId2",
                AssignedToProject_Id = "dummyProjId1",
                IsActive_bl = true,
                Comments = "DummyComments2",
                AssignedToProject = project2
            };
            var dbEntries = (new List<AssemblyLogEntry> { dbEntry1, dbEntry2 }).AsQueryable();

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

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

            var assyLogEntryService = new AssemblyLogEntryService(mockDbContextScopeFac.Object, projectPerson1.Id);

            //Act
            var resultAssemblyLogEntrys = assyLogEntryService.GetAsync(new[] { "dummyEntryId1", "dummyEntryId2" }).Result;

            //Assert
            Assert.IsTrue(resultAssemblyLogEntrys.Count == 0);
        }