コード例 #1
0
        public void Should_map_all_properties()
        {
            var conference = BuildConferenceDetailsResponse();
            var response   = ConferenceCacheMapper.MapConferenceToCacheModel(conference);

            response.Id.Should().Be(conference.Id);
            response.HearingId.Should().Be(conference.Hearing_id);

            response.Participants.Count.Should().Be(conference.Participants.Count);

            var participant       = conference.Participants[0];
            var resultParticipant = response.Participants[0];

            resultParticipant.Id.Should().Be(participant.Id);
            resultParticipant.Username.Should().Be(participant.Username);
            resultParticipant.Role.Should().Be(participant.User_role);
            resultParticipant.HearingRole.Should().Be(participant.Hearing_role);
            resultParticipant.DisplayName.Should().Be(participant.Display_name);
            resultParticipant.FirstName.Should().Be(participant.First_name);
            resultParticipant.LastName.Should().Be(participant.Last_name);
            resultParticipant.ContactEmail.Should().Be(participant.Contact_email);
            resultParticipant.ContactTelephone.Should().Be(participant.Contact_telephone);

            var judge = response.Participants.First(x => x.HearingRole == "Judge");

            judge.IsJudge().Should().BeTrue();
            judge.IsWitness().Should().BeFalse();

            var witness = response.Participants.First(x => x.HearingRole == "Witness");

            witness.IsJudge().Should().BeFalse();
            witness.IsWitness().Should().BeTrue();
        }
コード例 #2
0
        public async Task GetOrAddConferenceAsync_should_return_conference_when_cache_contains_key()
        {
            var conferenceResponse   = CreateConferenceResponse();
            var conference           = ConferenceCacheMapper.MapConferenceToCacheModel(conferenceResponse);
            var serialisedConference = JsonConvert.SerializeObject(conference, SerializerSettings);
            var rawData = Encoding.UTF8.GetBytes(serialisedConference);

            _distributedCacheMock
            .Setup(x => x.GetAsync(conference.Id.ToString(), CancellationToken.None))
            .ReturnsAsync(rawData);

            var cache = new DistributedConferenceCache(_distributedCacheMock.Object);

            var result = await cache.GetOrAddConferenceAsync(conference.Id, It.IsAny <Func <Task <ConferenceDetailsResponse> > >());

            result.Should().BeEquivalentTo(conference);
        }
コード例 #3
0
        public async Task GetOrAddConferenceAsync_should_return_conference_when_cache_does_not_contains_key()
        {
            var conferenceResponse   = CreateConferenceResponse();
            var conference           = ConferenceCacheMapper.MapConferenceToCacheModel(conferenceResponse);
            var serialisedConference = JsonConvert.SerializeObject(conference, SerializerSettings);
            var rawData = Encoding.UTF8.GetBytes(serialisedConference);

            _distributedCacheMock
            .SetupSequence(x => x.GetAsync(conference.Id.ToString(), CancellationToken.None))
            .ReturnsAsync((byte[])null)
            .ReturnsAsync(rawData);

            _distributedCacheMock
            .Setup(x => x.SetAsync(conference.Id.ToString(), rawData, It.IsAny <DistributedCacheEntryOptions>(), CancellationToken.None));

            var cache = new DistributedConferenceCache(_distributedCacheMock.Object);

            var result = await cache.GetOrAddConferenceAsync(conference.Id, async() => await Task.FromResult(conferenceResponse));

            result.Should().BeEquivalentTo(conference);
        }