public void AssemblyDbService_EditExtAsync_UpdatesExistingEntries()
        {
            // 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 assemblyExt1 = new AssemblyExt { Id = "dummyEntryId1", Attr01 = "Attr01", Attr02 = "Attr02", Attr03 = "Attr03", Attr04 = "Attr04",
                ModifiedProperties = new string[] { "Attr01", "Attr02" } };
            var assemblyExt2 = new AssemblyExt { Id = "dummyEntryId2", Attr01 = "Attr05", Attr02 = "Attr06", Attr03 = "Attr07", Attr04 = "Attr08" };
            var assemblyExts = new AssemblyExt[] { assemblyExt1, assemblyExt2 };

            var assembly1 = new AssemblyDb { Id = "dummyEntryId1" };
            var assembly2 = new AssemblyDb { Id = "dummyEntryId2" };
            var assemblys = new AssemblyDb[] { assembly1, assembly2 };

            var dbEntry1 = new AssemblyExt { Id = "dummyEntryId1", Attr01 = "Attr09", Attr02 = "Attr10", Attr03 = "Attr11", Attr04 = "Attr12" };
            var dbEntry2 = new AssemblyExt { Id = "dummyEntryId2", Attr01 = "Attr13", Attr02 = "Attr14", Attr03 = "Attr15", Attr04 = "Attr16" };

            mockEfDbContext.Setup(x => x.Set<AssemblyExt>().FindAsync(assemblyExt1.Id)).Returns(Task.FromResult(dbEntry1));
            mockEfDbContext.Setup(x => x.Set<AssemblyExt>().FindAsync(assemblyExt2.Id)).Returns(Task.FromResult(dbEntry2));
            mockEfDbContext.Setup(x => x.Set<AssemblyDb>().FindAsync(assembly1.Id)).Returns(Task.FromResult(assembly1));
            mockEfDbContext.Setup(x => x.Set<AssemblyDb>().FindAsync(assembly2.Id)).Returns(Task.FromResult(assembly2));
            mockEfDbContext.Setup(x => x.Set<AssemblyExt>().Add(It.IsAny<AssemblyExt>())).Verifiable();
            mockEfDbContext.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult<int>(1));

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

            //Act
            assemblyService.EditExtendedAsync(assemblyExts).Wait();

            //Assert
            Assert.IsTrue(assemblyExt1.Attr01 == dbEntry1.Attr01); Assert.IsTrue(assemblyExt1.Attr02 == dbEntry1.Attr02);
            Assert.IsTrue(assemblyExt1.Attr03 != dbEntry1.Attr03); Assert.IsTrue(assemblyExt1.Attr04 != dbEntry1.Attr04);
            Assert.IsTrue(assemblyExt2.Attr01 != dbEntry2.Attr01); Assert.IsTrue(assemblyExt2.Attr02 != dbEntry2.Attr02);
            Assert.IsTrue(assemblyExt2.Attr03 != dbEntry2.Attr03); Assert.IsTrue(assemblyExt2.Attr04 != dbEntry2.Attr04);
            mockDbContextScopeFac.Verify(x => x.Create(DbContextScopeOption.JoinExisting), Times.Once);
            mockDbContextScope.Verify(x => x.DbContexts.Get<EFDbContext>(), Times.Once);
            mockEfDbContext.Verify(x => x.Set<AssemblyExt>().FindAsync(It.IsAny<string>()), Times.Exactly(2));
            mockEfDbContext.Verify(x => x.Set<AssemblyDb>().FindAsync(It.IsAny<string>()), Times.Never);
            mockEfDbContext.Verify(x => x.Set<AssemblyExt>().Add(It.IsAny<AssemblyExt>()), Times.Never);
            mockEfDbContext.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
        public void AssemblyDbService_EditExtAsync_ReturnsErrorDbIfNotInDB()
        {
            // 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 initialId = "dummyEntryId1";
            var assemblyExt1 = new AssemblyExt { Id = initialId, Attr01 = "Attr01", Attr02 = "Attr02", Attr03 = "Attr03", Attr04 = "Attr04" };
            var assemblyExts = new AssemblyExt[] { assemblyExt1 };

            var assembly1 = new AssemblyDb { Id = initialId };
            var assemblys = new AssemblyDb[] { assembly1 };

            mockEfDbContext.Setup(x => x.Set<AssemblyExt>().FindAsync(It.IsAny<string>())).Returns(Task.FromResult<AssemblyExt>(null));
            mockEfDbContext.Setup(x => x.Set<AssemblyDb>().FindAsync(assembly1.Id)).Returns(Task.FromResult<AssemblyDb>(null));
            mockEfDbContext.Setup(x => x.Set<AssemblyExt>().Add(assemblyExt1)).Returns(assemblyExt1);
            mockEfDbContext.Setup(x => x.SaveChangesAsync()).Returns(Task.FromResult<int>(1));

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

            //Act
            assemblyService.EditExtendedAsync(assemblyExts).Wait();

            //Assert
            mockDbContextScopeFac.Verify(x => x.Create(DbContextScopeOption.JoinExisting), Times.Once);
            mockDbContextScope.Verify(x => x.DbContexts.Get<EFDbContext>(), Times.Once);
            mockEfDbContext.Verify(x => x.AssemblyExts.FindAsync(initialId), Times.Once);
            mockEfDbContext.Verify(x => x.AssemblyDbs.FindAsync(initialId), Times.Once);
            mockEfDbContext.Verify(x => x.AssemblyExts.Add(assemblyExt1), Times.Never);
            mockEfDbContext.Verify(x => x.SaveChangesAsync(), Times.Once);
        }