public void ShouldActivateViewOnWatchItemAdded() { try { var mockRegionContentRegistry = new MockRegionViewRegistry(); ServiceLocator.SetLocatorProvider( () => new MockServiceLocator( () => mockRegionContentRegistry)); var watchListView = new MockWatchListView(); var regionManager = new MockRegionManager(); var region = new MockRegion(); region.Add(watchListView); regionManager.Regions.Add("MainRegion", region); var presentationModel = new MockWatchListPresentationModel { View = watchListView }; WatchListController controller = new WatchListController(regionManager, presentationModel); controller.Run(); presentationModel.WatchListItems.Add(new WatchItem("MySymbol", 10m)); Assert.IsTrue(region.ActivateCalled); Assert.AreSame(watchListView, region.ActivateArg); } finally { ServiceLocator.SetLocatorProvider(() => null); } }
public void ShouldRegisterWatchListViewOnRegion() { try { var mockRegionContentRegistry = new MockRegionViewRegistry(); ServiceLocator.SetLocatorProvider( () => new MockServiceLocator( () => mockRegionContentRegistry)); var presentationModel = new MockWatchListPresentationModel(); var watchListView = new MockWatchListView(); presentationModel.View = watchListView; WatchListController controller = new WatchListController(new MockRegionManager(), presentationModel); controller.Run(); Assert.AreEqual(1, mockRegionContentRegistry.RegisteredViews.Count); Assert.IsTrue(mockRegionContentRegistry.RegisteredViews.ContainsKey("MainRegion")); Assert.AreSame(watchListView, mockRegionContentRegistry.RegisteredViews["MainRegion"]); } finally { ServiceLocator.SetLocatorProvider(() => null); } }
public async Task GetCallsMediatRWithExpectedNotFoundResult() { // Arrange mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <IList <WatchListModel> >(null)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Get() as NotFoundObjectResult; // Assert mediatR.Verify(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>()), Times.Once()); Assert.NotNull(result); Assert.Equal("No watchlist WatchList found", result.Value); Assert.Equal(404, result.StatusCode); }
public async Task DeleteCallsMediatRWithExpectedNotFoundResult() { // Arrange mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <DeleteWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <WatchListModel>(null)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Delete(1) as NotFoundObjectResult; // Assert mediatR.Verify(m => m.Send(It.IsAny <DeleteWatchListRequest>(), It.IsAny <CancellationToken>()), Times.Once()); Assert.NotNull(result); Assert.Equal("WatchList Not exists in the DB or error occurred", result.Value); Assert.Equal(404, result.StatusCode); }
public async Task GetCallsMediatRWithExpectedResult() { // Arrange mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <GetWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(GetWatchListResponse())); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Get() as OkObjectResult; // Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); var watchListModel = result.Value as IList <WatchListModel>; Assert.NotNull(watchListModel); Assert.Equal(2, watchListModel.Count); }
public async Task DeleteCallsMediatRWithExpectedResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <DeleteWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(watchListModel)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Delete(1) as OkObjectResult; // Assert Assert.NotNull(result); Assert.Equal(200, result.StatusCode); }
public async Task PostCallsWithInValidModelStateExpectedNotFoundResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498 }; mediatR = new Mock <IMediator>(); controller = new WatchListController(mediatR.Object); controller.ModelState.AddModelError("Comments", "Comments is Required"); // Act var result = await controller.Post(watchListModel) as BadRequestObjectResult; // Assert Assert.NotNull(result); Assert.Equal(400, result.StatusCode); }
public async Task PostCallsMediatRWithExpectedNotFoundResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <WatchListModel>(null)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Post(watchListModel) as ObjectResult; // Assert mediatR.Verify(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>()), Times.Once()); Assert.NotNull(result); Assert.Equal(409, result.StatusCode); }
public async Task PutCallsWithInValidModelStateExpectedNotFoundResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <UpdateWatchListRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <WatchListModel>(null)); controller = new WatchListController(mediatR.Object); controller.ModelState.AddModelError("Comments", "Comments is Required"); // Act var result = await controller.Put(watchListModel) as BadRequestObjectResult; // Assert Assert.NotNull(result); Assert.Equal(400, result.StatusCode); }
public async Task PostCallsMediatRWithExpectedResult() { // Arrange var watchListModel = new WatchListModel { MovieId = 383498, Comments = "Deadpool 2 is review good" }; mediatR = new Mock <IMediator>(); mediatR.Setup(m => m.Send(It.IsAny <CreateBookingRequest>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult(watchListModel)); controller = new WatchListController(mediatR.Object); // Act var result = await controller.Post(watchListModel) as CreatedResult; // Assert Assert.NotNull(result); Assert.Equal(201, result.StatusCode); var watchListModels = result.Value as WatchListModel; Assert.NotNull(watchListModels); Assert.Equal("Deadpool 2 is review good", watchListModels.Comments); }