示例#1
0
        public async Task GetSessionByIdSuccessful()
        {
            var id      = 1;
            var session = new BackEnd.Data.Session
            {
                ID       = id,
                Abstract = "abstract",
                Title    = "title"
            };

            var sessionsRepositoryStub = new Mock <ISessionsRepository>();

            sessionsRepositoryStub.Setup(s => s.GetByIdAsync(It.IsAny <int>(), It.IsAny <CancellationToken>())).ReturnsAsync(session);

            var speakersRepositoryStub = new Mock <ISpeakersRepository>();

            var cacheStub = new Mock <IDistributedCache>();

            cacheStub.Setup(c => c.GetAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).ReturnsAsync((byte[])null);

            var controller = new SessionsController(sessionsRepositoryStub.Object, speakersRepositoryStub.Object, cacheStub.Object);

            var result         = (await controller.Get(id)).Value;
            var expectedResult = GetSingleSessionResponse();

            Assert.Equal(expectedResult.ID, result.ID);
            Assert.Equal(expectedResult.Title, result.Title);
            Assert.Equal(expectedResult.Abstract, result.Abstract);
        }
示例#2
0
 public static ConferenceDTO.SessionResponse MapSessionResponse(this Session session) =>
 new ConferenceDTO.SessionResponse()
 {
     Id        = session.Id,
     Abstract  = session.Abstract,
     StartTime = session.StartTime,
     EndTime   = session.EndTime,
     Title     = session.Title,
     Speakers  = session.SessionSpeakers?.Select(ss => new ConferenceDTO.Speaker()
     {
         Id   = ss.SpeakerId,
         Name = ss.Speaker.Name
     }).ToList(),
     TrackId = session.TrackId,
     Track   = new ConferenceDTO.Track
     {
         Id   = session?.TrackId ?? 0,
         Name = session.Track?.Name
     }
 };