public async Task WhenSaveRecordIfNotExistCreateNewElseUpdateExisted()
        {
            var person = _fixture.Create <Person>();

            person.Created = _now;
            await TransactionManager.DoInTransactionAsync(
                async() =>
            {
                var rows = await _personDataService.SaveAsync(person);

                rows.Should().Be(1);

                var actual = await _personDataService.GetAsync(person.Id);

                actual.Id.Should().Be(person.Id);
                actual.First.Should().Be(person.First);
                actual.Last.Should().Be(person.Last);
                actual.Age.Should().Be(person.Age);
                actual.Gender.Should().Be(person.Gender);
                actual.Created.Should().Be(_now);

                var newAge = _fixture.Create <int>();
                var date   = _now.AddHours(1);

                person.Age     = newAge;
                person.Created = date;
                rows           = await _personDataService.SaveAsync(person);

                rows.Should().Be(1);

                actual = await _personDataService.GetAsync(person.Id);

                actual.Id.Should().Be(person.Id);
                actual.First.Should().Be(person.First);
                actual.Last.Should().Be(person.Last);
                actual.Age.Should().Be(newAge);
                actual.Gender.Should().Be(person.Gender);
                actual.Created.Should().Be(_now);
                actual.Updated.Should().Be(date);
            });
        }
Beispiel #2
0
        public async Task WhenPostPersonItShouldReturn1()
        {
            var person = _fixture.Create <Person>();

            _dataService
            .SaveAsync(person)
            .Returns(1);

            var actual = await _personsController.PostAsync(person);

            actual
            .Value
            .Should()
            .Be(1);
        }
Beispiel #3
0
        public async Task <ActionResult <int> > PostAsync(Person person)
        {
            if (person == null)
            {
                return(BadRequest());
            }

            var result = 0;

            await _transactionManager.DoInTransactionAsync(async() =>
            {
                result = await _dataService.SaveAsync(person);
            });

            return(result);
        }