Пример #1
0
        public void ComponentStatusService_GetAsync_ReturnsComponentStatussByIds()
        {
            //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 ComponentStatus { Id = "dummyEntryId1", CompStatusName = "Name1", CompStatusAltName = "NameAlt1", IsActive_bl = false };
            var dbEntry2 = new ComponentStatus { Id = "dummyEntryId2", CompStatusName = "Name2", CompStatusAltName = "NameAlt2", IsActive_bl = true };
            var dbEntry3 = new ComponentStatus { Id = "dummyEntryId3", CompStatusName = "Name3", CompStatusAltName = "NameAlt3", IsActive_bl = true };
            var dbEntries = (new List<ComponentStatus> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

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

            var compStatusService = new ComponentStatusService(mockDbContextScopeFac.Object, "DummyUserId");

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

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

        }
Пример #2
0
 public async Task<ActionResult> Edit(ComponentStatus[] records)
 {
     ViewBag.ServiceName = "ComponentStatusService.EditAsync";
     var newEntryIds = await compStatusService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True", newEntryIds = newEntryIds });
 }