Пример #1
0
        public void async_crud_process_succeeds()
        {
            var entityId = 787;
            var entity   = new Author
            {
                Id            = entityId
                , AuthorCode  = "ABC-12345"
                , FirstName   = "Unit"
                , LastName    = "Test"
                , PhoneNumber = "3607259465"
                , Address     = "549 SW Olympic Ave"
                , City        = "Lacey"
                , State       = "WA"
                , ZipCode     = "98503"
                , Contract    = false
            };

            var savedEntity   = _repository.AddAsync(entity).Result;
            var updatedEntity = _repository.GetByIdAsync(entityId).Result;

            using (new AssertionScope())
            {
                savedEntity.Should().NotBeNull();
                savedEntity.Id.Should().Be(entityId);
                savedEntity.FirstName.Should().Be("Unit");
                savedEntity.PhoneNumber.Should().Be("3607259465");
                savedEntity.Contract.Should().BeFalse();
                savedEntity.AuthorCode.Should().Be("ABC-12345");

                updatedEntity.Should().NotBeNull();
                updatedEntity.Id.Should().Be(entityId);
                updatedEntity.FirstName.Should().Be("Unit");
                updatedEntity.PhoneNumber.Should().Be("3607259465");
                updatedEntity.Contract.Should().BeFalse();
                updatedEntity.AuthorCode.Should().Be("ABC-12345");

                updatedEntity.FirstName = "UnitUnit";
                updatedEntity.LastName  = "TestTest";
                updatedEntity.Contract  = true;

                _ = _repository.UpdateAsync(updatedEntity);

                updatedEntity = _repository.GetByIdAsync(entityId).Result;
                updatedEntity.FirstName.Should().Be("UnitUnit");
                updatedEntity.LastName.Should().Be("TestTest");
                updatedEntity.Contract.Should().BeTrue();
                updatedEntity.AuthorCode.Should().Be("ABC-12345");

                _ = _repository.DeleteAsync(updatedEntity);
                _repository.GetByIdAsync(entityId).Result.Should().BeNull();
            }
        }