Exemplo n.º 1
0
 public PostPersonTests(MockWebApplicationFactory <Startup> appFactory)
 {
     _dbFixture     = appFactory.DynamoDbFixture;
     _snsFixture    = appFactory.SnsFixture;
     _personFixture = new PersonFixture(_dbFixture.DynamoDbContext, _snsFixture.SimpleNotificationService);
     _steps         = new PostPersonSteps(appFactory.Client);
 }
Exemplo n.º 2
0
 public void MakePersonFixture()
 {
     service       = new Service.Service();
     personFixture = new PersonFixture {
         Processor = service
     };
 }
Exemplo n.º 3
0
        public async Task ThenThePersonDetailsAreUpdated(PersonFixture personFixture)
        {
            _lastResponse.StatusCode.Should().Be(HttpStatusCode.NoContent);
            var result = await personFixture._dbContext.LoadAsync <PersonDbEntity>(personFixture.Person.Id).ConfigureAwait(false);

            result.FirstName.Should().Be(personFixture.UpdatePersonRequest.FirstName);
            result.Surname.Should().Be(personFixture.UpdatePersonRequest.Surname);
            result.DateOfDeath.Should().Be(personFixture.UpdatePersonRequest.DateOfDeath);
            result.VersionNumber.Should().Be(1);
            result.LastModified.Should().BeCloseTo(DateTime.UtcNow, 1500);
        }
Exemplo n.º 4
0
        public async Task ThenThePersonDetailsAreReturnedAndIdIsNotEmpty(PersonFixture personFixture)
        {
            _lastResponse.StatusCode.Should().Be(HttpStatusCode.Created);

            var responseContent = await _lastResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

            var apiPerson = JsonSerializer.Deserialize <PersonResponseObject>(responseContent, CreateJsonOptions());

            apiPerson.Id.Should().NotBeEmpty();

            var dbRecord = await personFixture._dbContext.LoadAsync <PersonDbEntity>(apiPerson.Id).ConfigureAwait(false);

            apiPerson.Should().BeEquivalentTo(new ResponseFactory(null).ToResponse(dbRecord.ToDomain()),
                                              config => config.Excluding(y => y.Links));
            dbRecord.VersionNumber.Should().Be(0);
            dbRecord.LastModified.Should().BeCloseTo(DateTime.UtcNow, 1500);

            await personFixture._dbContext.DeleteAsync <PersonDbEntity>(dbRecord.Id).ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public async Task ThenThePersonUpdatedEventIsRaised(PersonFixture personFixture, ISnsFixture snsFixture)
        {
            var dbPerson = await personFixture._dbContext.LoadAsync <PersonDbEntity>(personFixture.Person.Id).ConfigureAwait(false);

            Action <string, PersonDbEntity> verifyData = (dataAsString, person) =>
            {
                var dataDic = JsonSerializer.Deserialize <Dictionary <string, object> >(dataAsString, CreateJsonOptions());
                dataDic["title"].ToString().Should().Be(Enum.GetName(typeof(Title), person.Title.Value));
                dataDic["firstName"].ToString().Should().Be(person.FirstName);
                dataDic["surname"].ToString().Should().Be(person.Surname);
            };

            Action <PersonSns> verifyFunc = (actual) =>
            {
                actual.CorrelationId.Should().NotBeEmpty();
                actual.DateTime.Should().BeCloseTo(DateTime.UtcNow, 1000);
                actual.EntityId.Should().Be(personFixture.PersonId);
                verifyData(actual.EventData.OldData.ToString(), personFixture.Person);
                verifyData(actual.EventData.NewData.ToString(), dbPerson);
                actual.EventType.Should().Be(UpdatePersonConstants.EVENTTYPE);
                actual.Id.Should().NotBeEmpty();
                actual.SourceDomain.Should().Be(UpdatePersonConstants.SOURCEDOMAIN);
                actual.SourceSystem.Should().Be(UpdatePersonConstants.SOURCESYSTEM);
                actual.User.Email.Should().Be("*****@*****.**");
                actual.User.Name.Should().Be("Tester");
                actual.Version.Should().Be(UpdatePersonConstants.V1VERSION);
            };

            var snsVerifer = snsFixture.GetSnsEventVerifier <PersonSns>();
            var snsResult  = await snsVerifer.VerifySnsEventRaised(verifyFunc);

            if (!snsResult && snsVerifer.LastException != null)
            {
                throw snsVerifer.LastException;
            }
        }