Example #1
0
        public void Insert_WithExistingDescriptionAndLanguage_Success()
        {
            var options = TestUtilities.GetDbContextOptions();

            var pack = new Pack {
                Name = "Test Pack", Description = "Test Description", Language = "ru"
            };
            var packDuplicated = new Pack {
                Name = "Test Pack1", Description = "Test Description", Language = "ru"
            };

            // Run the test against one instance of the context
            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);
                repo.InsertAsync(pack).GetAwaiter().GetResult();
                repo.InsertAsync(packDuplicated).GetAwaiter().GetResult();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new FillerDbContext(options))
            {
                var repo                = new PackRepository(context);
                var savedPack           = repo.GetAll().FirstOrDefault(p => p.Name == pack.Name && p.Description == pack.Description);
                var savedPackDuplicated = repo.GetAll().FirstOrDefault(p => p.Name == packDuplicated.Name && p.Description == packDuplicated.Description);
                Assert.NotNull(savedPack);
                Assert.NotNull(savedPackDuplicated);
                Assert.GreaterOrEqual(savedPack.Id, 1);
                Assert.GreaterOrEqual(savedPackDuplicated.Id, 1);
            }
        }
Example #2
0
        public void Edit_ExistingPack_Success()
        {
            var options = TestUtilities.GetDbContextOptions();

            var pack = new Pack {
                Name = "Test Pack", Description = "Test Description", Language = "ru"
            };
            const string newName        = "new name";
            const string newDescription = "new description";
            const string newLanguage    = "en";

            // Run the test against one instance of the context
            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);
                repo.InsertAsync(pack).GetAwaiter().GetResult();
                pack.Name        = newName;
                pack.Description = newDescription;
                pack.Language    = newLanguage;
                repo.UpdateAsync(pack);
            }

            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);

                var updatedPack = repo.GetAll().Single();
                Assert.AreEqual(updatedPack.Name, pack.Name);
                Assert.AreEqual(updatedPack.Language, pack.Language);
                Assert.AreEqual(updatedPack.Description, pack.Description);
            }
        }
Example #3
0
        public void Insert_WithExistingId_Failed()
        {
            var options = TestUtilities.GetDbContextOptions();

            var pack = new Pack {
                Id = 1, Name = "Test Pack", Description = "Test Description", Language = "ru"
            };
            var packDuplicated = new Pack {
                Id = 1, Name = "Test Pack1", Description = "Test Description1", Language = "ru"
            };

            // Run the test against one instance of the context
            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);
                repo.InsertAsync(pack).GetAwaiter().GetResult();
                Assert.Throws <InvalidOperationException>(() => repo.InsertAsync(packDuplicated).GetAwaiter().GetResult());
            }
        }
Example #4
0
        public void Delete_Existing_Success()
        {
            var options = TestUtilities.GetDbContextOptions();

            var pack = new Pack {
                Name = "Test Pack111", Description = "Test Description", Language = "ru"
            };

            // Run the test against one instance of the context
            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);
                repo.InsertAsync(pack).GetAwaiter().GetResult();
                repo.DeleteAsync(pack).GetAwaiter().GetResult();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new FillerDbContext(options))
            {
                var repo = new PackRepository(context);
                Assert.IsEmpty(repo.GetAll());
            }
        }