Example #1
0
        public async Task update_should_success()
        {
            // Arrange
            using (var dbContext = CreateDbContext())
            {
                // Arrange
                var repo        = new TestModelRepository(dbContext);
                var expectedAge = 2;

                var model = new TestModel
                {
                    Age = 1
                };

                await repo.InsertAsync(model);

                // Actions.

                model.Age = expectedAge;

                await repo.UpdateAsync(model);

                dbContext.SaveChanges();

                var model2 = dbContext.TestModels.Find(model.Id);

                // Assertions
                model.Id.Should().NotBeNullOrEmpty();

                model2.Should().NotBeNull();
                model2.Age.Should().Be(expectedAge);
            }
        }
Example #2
0
        public void ReadModelRepositoryDeleteMethodShouldThrowExceptionIfNullIsAdded()
        {
            var    repository = new TestModelRepository();
            Action act        = () => repository.Delete(null);

            act.ShouldThrow <ModelRepositoryDeleteException>();
        }
Example #3
0
        public void ReadModelRepositoryDeleteMethodShouldThrowExceptionIfItemWIthEmptyIsAdded()
        {
            var    repository = new TestModelRepository();
            Action act        = () => repository.Delete(new Test(Guid.Empty));

            act.ShouldThrow <ModelRepositoryDeleteException>();
        }
Example #4
0
        public void ReadModelRepositoryShouldNotThrowExceptionIfNotItemFound()
        {
            var    repository = new TestModelRepository();
            Action act        = () => repository.GetById(Guid.NewGuid());

            act.ShouldNotThrow();
        }
Example #5
0
        public void IncludeDeeplyNestedResourceTest()
        {
            // Setup
            var data         = TestModelRepository.GetIncludeDeeplyNestedResourceTestData();
            var jsonDocument = JsonApiDocumentExtensions.CreateDocumentFromApiResource <TestModelCompoundApiResource>(data, @"http://test.com");

            // add includes
            jsonDocument.IncludeRelation <TestModelCompoundApiResource>(data, "bigData.children.toOne", @"http://test.com");

            // Serialize
            var jsonString = JsonConvert.SerializeObject(jsonDocument, Formatting.Indented);

            // Deserialize
            var deserializedDocument = JsonConvert.DeserializeObject <JsonApiDocument>(jsonString);

            // Retrieve Data
            var retrievedData = deserializedDocument.ToObject <TestModelCompound, TestModelCompoundApiResource>();

            retrievedData.BigData          = deserializedDocument.GetIncludedResource <TestModelToN, TestModelToNApiResource>(retrievedData.BigDataId);
            retrievedData.BigData.Children = retrievedData.BigData.ChildrenIds.Select(item => deserializedDocument.GetIncludedResource <TestModelToOne, TestModelToOneApiResource>(item));
            retrievedData.SmallData        = deserializedDocument.GetIncludedResource <TestModelToOne, TestModelToOneApiResource>(retrievedData.SmallDataId);

            // Compare
            Assert.AreEqual(data.MyIdProperty, retrievedData.MyIdProperty);
        }
Example #6
0
        public void ReadModelRepositoryShouldThrowExceptionIfDuplicateItemIsAdded()
        {
            var testItem   = new Test(Guid.NewGuid());
            var repository = new TestModelRepository();

            repository.Add(testItem);

            Action act = () => repository.Add(testItem);

            act.ShouldThrow <ModelRepositoryAddException>();
        }
Example #7
0
        public void ReadModelRepositoryShouldReturnAnItemById()
        {
            var guid = Guid.NewGuid();
            var item = new Test(guid)
            {
                Name = "Testitem"
            };

            var repository = new TestModelRepository();

            repository.Add(item);
            repository.GetById(guid).Should().Be(item);
        }
Example #8
0
        public void ReadModelRepositoryShouldReturnsAllItems()
        {
            var item1 = new Test(Guid.NewGuid())
            {
                Name = "Testitem 1"
            };
            var item2 = new Test(Guid.NewGuid())
            {
                Name = "Testitem 2"
            };

            var repository = new TestModelRepository();

            repository.Add(item1);
            repository.Add(item2);
            repository.GetAll().Count().Should().Be(2);
        }
Example #9
0
        public void ReadModelRepositoryShouldUpdateAnItem()
        {
            var guid = Guid.NewGuid();
            var item = new Test(guid)
            {
                Name = "Testitem"
            };
            var itemUpdate = new Test(guid)
            {
                Name = "Testitem Update"
            };

            var repository = new TestModelRepository();

            repository.Add(item);
            repository.Update(itemUpdate);
            repository.GetById(guid).Name.Should().Be("Testitem Update");
        }
Example #10
0
        public void ReadModelRepositoryShouldReturnNullIfNotItemFound()
        {
            var repository = new TestModelRepository();

            repository.GetById(Guid.NewGuid()).Should().Be(null);
        }