Example #1
0
        public async void TestCreateAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "SchemaDatabase")
                          .Options;

            var dbContext = new ApplicationDbContext(options);

            var repo = new SchemaRepository(dbContext);
            // Act
            var result = await repo.CreateAsync(new Schema { SavedDate = DateTime.Now, SchemaJson = "{}" });

            // Assert
            Assert.True(result is Schema);
        }
Example #2
0
        public async void TestGetByIdAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "SchemaDatabase")
                          .Options;

            var dbContext = new ApplicationDbContext(options);
            var repo      = new SchemaRepository(dbContext);
            var json      = "{id: 123}";
            // Act
            var newSchema = await repo.CreateAsync(new Schema { SavedDate = DateTime.Now, SchemaJson = json });

            var createdId = newSchema.Id;

            var searchResult = await repo.GetByIdAsync(createdId);

            // Assert
            Assert.True(createdId > 0 && searchResult.SchemaJson == json);
        }
Example #3
0
        public async void TestDeleteAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "SchemaDatabase")
                          .Options;

            var dbContext = new ApplicationDbContext(options);
            var repo      = new SchemaRepository(dbContext);
            // Act
            var newSchema = await repo.CreateAsync(new Schema { SavedDate = DateTime.Now, SchemaJson = "{id: 123}" });

            var createdId = newSchema.Id;
            await repo.DeleteAsync(createdId);

            var searchResult = await repo.FindByAsync(x => x.Id == createdId);

            if (searchResult.Count() == 0)
            {
            }
            // Assert
            Assert.True(createdId > 0 && searchResult.Count() == 0);
        }
Example #4
0
        public async void TestUpdateAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "SchemaDatabase")
                          .Options;

            var dbContext = new ApplicationDbContext(options);
            var repo      = new SchemaRepository(dbContext);
            var newJson   = "{id: 234}";
            // Act
            var newSchema = await repo.CreateAsync(new Schema()
            {
                SavedDate = DateTime.Now, SchemaJson = "{id: 123}"
            });

            var id = newSchema.Id;

            newSchema.SchemaJson = newJson;
            var result = await repo.UpdateAsync(id, newSchema);

            // Assert
            Assert.True(result.SchemaJson == newJson);
        }