public void LocationTypeService_GetAsync_ReturnsLocationTypesByIds()
        {
            //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 LocationType { Id = "dummyEntryId1", LocTypeName = "Name1", LocTypeAltName = "NameAlt1", IsActive_bl = false };
            var dbEntry2 = new LocationType { Id = "dummyEntryId2", LocTypeName = "Name2", LocTypeAltName = "NameAlt2", IsActive_bl = true };
            var dbEntry3 = new LocationType { Id = "dummyEntryId3", LocTypeName = "Name3", LocTypeAltName = "NameAlt3", IsActive_bl = true };
            var dbEntries = (new List<LocationType> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable();

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

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

            var locationTypeService = new LocationTypeService(mockDbContextScopeFac.Object, "dummyuserId");

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

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

        }
示例#2
0
 public async Task<ActionResult> Edit(LocationType[] records)
 {
     ViewBag.ServiceName = "LocationTypeService.EditAsync";
     var newEntryIds = await locationTypeService.EditAsync(records).ConfigureAwait(false);
     return DbJson(new { Success = "True", newEntryIds = newEntryIds });
 }