public void GetSession_GetResult_NotFail_Test() { int expectedSessionId = 10; bool called = false; var expected = new Session() { SessionId = expectedSessionId }; IEventDefinitionRepository eventRepository = new StubIEventDefinitionRepository(); ISessionRepository sessionRepository = new StubISessionRepository() { GetWithUserInfoInt32Int32 = (userId, eventId) => { Assert.AreEqual(expectedSessionId, eventId); called = true; return(expected); } }; using (ShimsContext.Create()) { MyEvents.Api.Authentication.Fakes.ShimMyEventsToken myeventToken = new Authentication.Fakes.ShimMyEventsToken(); myeventToken.RegisteredUserIdGet = () => { return(0); }; ShimMyEventsToken.GetTokenFromHeader = () => { return(myeventToken); }; var target = new SessionsController(sessionRepository, eventRepository); Session actual = target.Get(expectedSessionId); Assert.IsTrue(called); Assert.AreEqual(expectedSessionId, actual.SessionId); } }
public void Sessions_Controller_Get_Should_Be_Ok() { // Arrange var id = 1; _session.Setup(x => x.Id).Returns(id); _session.Setup(x => x.Lounge).Returns(ObjectMother.GetDefaultLounge()); _session.Setup(x => x.Movie).Returns(ObjectMother.GetDefaultMovie()); _session.Setup(x => x.TakenSeats).Returns(new Collection <Seat>()); var response = new List <Session>() { _session.Object }.AsQueryable(); _sessionServiceMock.Setup(s => s.GetAll()).Returns(response); var odataOptions = GetOdataQueryOptions <Session>(_sessionsController); // Action var callback = _sessionsController.Get(odataOptions); // Assert _sessionServiceMock.Verify(s => s.GetAll(), Times.Once); var httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <PageResult <SessionGridViewModel> > >().Subject; httpResponse.Content.Should().NotBeNullOrEmpty(); httpResponse.Content.First().Id.Should().Be(id); }
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); }
public async Task GetSessionsSuccessful() { var sessionsRepositoryStub = new Mock <ISessionsRepository>(); sessionsRepositoryStub.Setup(s => s.GetAll()).Returns(GetAllSessions()); 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()).Value; var expectedResult = GetSessionResponses(); Assert.Equal(expectedResult.Count, result.Count); Assert.Equal(expectedResult.ElementAt(0).ID, result.ElementAt(0).ID); Assert.Equal(expectedResult.ElementAt(0).Title, result.ElementAt(0).Title); Assert.Equal(expectedResult.ElementAt(0).Abstract, result.ElementAt(0).Abstract); Assert.Equal(expectedResult.ElementAt(1).ID, result.ElementAt(1).ID); Assert.Equal(expectedResult.ElementAt(1).Title, result.ElementAt(1).Title); Assert.Equal(expectedResult.ElementAt(1).Abstract, result.ElementAt(1).Abstract); }
public void Get_MissingSession_Returns404() { var sessionServiceMock = new Mock <ISessionService>(); sessionServiceMock.Setup(s => s.Get(It.IsAny <int>())).Returns <Session>(null); var sessionsController = new SessionsController(sessionServiceMock.Object); var result = sessionsController.Get(0); result.Result.Should().BeOfType <NotFoundResult>(); }
public void Post() { var controller = new SessionsController(); var formData = ""; controller.Post(formData); var session = controller.Get(0); Assert.IsNotNull(session); }
public void Get() { var controller = new SessionsController(); var result = controller.Get(); Assert.IsInstanceOfType(result, typeof(Array)); var array = (string[])result; Assert.IsTrue(array.Length >= 0); }
public void TestGetOneIDNotFound() { //Arrange SessionsController controller = new SessionsController(); //Act IActionResult p = controller.Get(123); NotFoundResult result = p as NotFoundResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, 404); }
public void TestGetOne() { //Arrange SessionsController controller = new SessionsController(); //Act IActionResult p = controller.Get(1); OkObjectResult result = p as OkObjectResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, 200); }
public void TestGetAll() { //Arrange List<Session> sessions = new List<Session>(); SessionsController controller = new SessionsController(); bool check; //Act sessions = controller.Get(); check = sessions.Count > 0; //Assert Assert.AreEqual(check, true); }