Exemplo n.º 1
0
            public async void GivenDatabaseDoesNotContainObject_ItShouldAddAnObjectAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                TestObject addedObject;

                using (var context = new TestContext(options))
                {
                    var repository = new AsyncRepository <TestObject>(context);
                    addedObject = await repository.AddAsync(new TestObject { Name = "Test" });
                }

                using (var context = new TestContext(options))
                {
                    var returnedObject = context.TestObjects.Find(addedObject.Id);
                    addedObject.Should().NotBeNull("an object should be added");
                    returnedObject.Should().BeEquivalentTo(addedObject);
                }
            }
Exemplo n.º 2
0
            public async void GivenDatabaseContainsSameObject_ItShouldReplaceTheObjectAsync()
            {
                var options = new DbContextOptionsBuilder <TestContext>()
                              .UseInMemoryDatabase(Helper.GetCallerName())
                              .Options;
                var        addedEntity = new TestObject(id: 1, name: "TestObject");
                TestObject actualEntity;

                using (var context = new TestContext(options))
                {
                    context.Add(addedEntity);
                }

                using (var context = new TestContext(options))
                {
                    var newEntity  = new TestObject(id: 1, name: "NewTestObject");
                    var repository = new AsyncRepository <TestObject>(context);
                    actualEntity = await repository.AddAsync(newEntity);
                }

                actualEntity.Should().BeEquivalentTo(new TestObject(1, "NewTestObject"));
            }