public void Details() { // Arrange var id = 20; var name = "Kanal"; var scenarios = new List <NcScenario>(); var channel = new NcChannel { Id = id, Name = name }; var mock = new Mock <IChannelManager>(); mock.Setup(x => x.FindById(id)).Returns(channel); mock.Setup(x => x.GetScenariosByChannelId(id)).Returns(scenarios); var expected = new ChannelViewModel { Id = id, Name = name, Scenarios = mapper.MapEnumerable <ScenarioListDTO>(scenarios).ToList(), }.ToExpectedObject(); // Act var controller = new ChannelsController(mock.Object, mapper); var result = controller.Details(id); // Assert var actual = (result as ViewResult)?.Model; expected.ShouldEqual(actual); }
public void GetChannelById_ExistingChannel_ShouldReturn200OK_CorrectChannelData() { // Arrange -> create a few channels var dataLayerMock = new MessagesDataMock(); var channelsMock = dataLayerMock.Channels; channelsMock.Add(new Channel() { Id = 1, Name = "Channel #1" }); channelsMock.Add(new Channel() { Id = 2, Name = "Channel #2" }); channelsMock.Add(new Channel() { Id = 3, Name = "Channel #3" }); // Act -> Get channel by ID var channelsController = new ChannelsController(dataLayerMock); this.SetupControllerForTesting(channelsController, "channels"); var httpResponse = channelsController.GetChannelById(2) .ExecuteAsync(new CancellationToken()).Result; // Assert -> HTTP status code 200 (OK) + correct channel data Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); var channel2 = httpResponse.Content.ReadAsAsync <ChannelModel>().Result; Assert.AreEqual(2, channel2.Id); Assert.AreEqual("Channel #2", channel2.Name); }
public void GetChannelById_NonExistingChannel_ShouldReturn404NotFound() { // Arrange -> create a few channels var dataLayerMock = new MessagesDataMock(); var channelsMock = dataLayerMock.Channels; channelsMock.Add(new Channel() { Id = 1, Name = "Channel #1" }); channelsMock.Add(new Channel() { Id = 2, Name = "Channel #2" }); channelsMock.Add(new Channel() { Id = 3, Name = "Channel #3" }); // Act -> Get channel by ID var channelsController = new ChannelsController(dataLayerMock); this.SetupControllerForTesting(channelsController, "channels"); var httpResponse = channelsController.GetChannelById(20) .ExecuteAsync(new CancellationToken()).Result; // Assert -> HTTP status code 404 (Not Found) Assert.AreEqual(HttpStatusCode.NotFound, httpResponse.StatusCode); }
public void StopChannelTest() { var account = App.Config.GetDefaultAccount(); var context = account.GetContext(); var controller = new ChannelsController(); var channels = context.Channels.ToList(); var channel = channels.FirstOrDefault(c => c.State == ChannelState.Running); if (channel != null) { controller.Stop(account.AccountName, channel.Id.NimbusIdToRawGuid()); channel = context.Channels.Where(c => c.Id == channel.Id).FirstOrDefault(); Assert.AreEqual(ChannelState.Stopping, channel.State); } //trying to start a running channel fails. channel = channels.FirstOrDefault(c => c.State != ChannelState.Stopped); if (channel != null) { try { controller.Stop(account.AccountName, channel.Id.NimbusIdToRawGuid()); } catch (HttpResponseException he) { Assert.AreEqual(HttpStatusCode.PreconditionFailed, he.Response.StatusCode); } } }
public void GetChannelControllerTest() { var mds = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0]; var controller = new ChannelsController(); Assert.IsNotNull(controller.DataAccess); Assert.IsInstanceOf <ChannelsController>(controller); }
public ChannelsControllerTests() { var configuration = TestHelpers.SlackConfiguration(); _restClient = new Mock <IRestClient>(); _queryStringFactory = new Mock <IQueryStringFactory>(); _controller = new ChannelsController(configuration.Object, _restClient.Object, _queryStringFactory.Object); }
public void SetUp() { ServiceLocatorInitializer.Init(); channelManagementService = MockRepository.GenerateMock <IChannelManagementService>(); channelsController = new ChannelsController(channelManagementService); }
public void GetChannelByLongChannelIdTest() { var ctrlr = new ChannelsController(); string acct = "dashboardbl2"; //channels/; string id = "0405bb3a-fa37-4e26-ad49-fb1473b48093"; var result = ctrlr.GetChannelById(acct, id); Assert.IsNotNull(result); }
public void Test_ChannelEndpoint_NoSchools_Returns_Contents() { // Arrange _sut = new ChannelsController(mockSchoolsService.Object); // Act var result = _sut.GetChannels("http://noschools/"); // Assert Assert.IsType <NoContentResult>(result); Assert.Equal(0, _sut.ModelState.ErrorCount); }
public void Test_ChannelEndpoint_WithUrlNotbackslash_Returns_OK() { // Arrange _sut = new ChannelsController(mockSchoolsService.Object); // Act var result = _sut.GetChannels("http://localhost"); // Assert Assert.IsType <OkObjectResult>(result); Assert.Equal(0, _sut.ModelState.ErrorCount); }
public void GetChannelByNameTest() { var account = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0]; var controller = new ChannelsController(); var channel = account.GetContext().Channels.FirstOrDefault(); Assert.IsNotNull(channel, "Channel not created in cloud context"); var channelDetails = controller.GetChannelByName(channel.Name); Assert.IsNotNull(channelDetails, "Channel data not saved to database"); Assert.AreEqual(channel.Name, channelDetails.NameShort); }
public ChannelsControllerTests() { var services = MockServices.ScopedServiceProvider; _controller = new ChannelsController(services.GetService <IDiscordClient>()) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = new ClaimsPrincipal(new ClaimsIdentity()) } } }; }
public void GetChannelsTest() { var mds = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0]; var controller = new ChannelsController(); try { var channels = controller.GetAllChannels(mds.AccountName); Assert.IsNotNull(channels); Assert.IsTrue(channels.Count() >= 0); } catch (Exception ex) { Assert.Fail("Excetion: {0}", ex); } }
public async Task Post_CalledRepositoryInsert() { // arrange var repository = new Mock <IChannelRepository>(); repository.Setup(x => x.InsertAsync(It.IsAny <NcChannel>())).Returns(Task.CompletedTask); var controller = new ChannelsController(It.IsAny <ILogger <ChannelsController> >(), repository.Object, mapper, It.IsAny <ChannelManager>(), null) .SetValidator(); // act await controller.Post(""); // assert repository.VerifyAll(); }
public void GetChannel_Return200Ok() { //arrange var serviceMock = new Mock <IChannelService>(); serviceMock.Setup(c => c.GetChannels()) .Returns(ServiceResult <IEnumerable <ChannelModel> > .SuccessResult( Enumerable.Empty <ChannelModel>())); var controller = new ChannelsController(serviceMock.Object); //act var response = controller.Get(); //assert Assert.IsType <OkObjectResult>(response); }
public void InsertSlateTest() { var account = App.Config.GetDefaultAccount(); var context = account.GetContext(); var controller = new ChannelsController(); var channels = context.Channels.ToList(); var channel = channels.FirstOrDefault(c => c.State == ChannelState.Running && c.EncodingType != ChannelEncodingType.None); if (channel != null) { var settings = new Models.SlateSettings { Duration = 30 }; var operation = controller.Slate(account.AccountName, channel.Id.NimbusIdToRawGuid(), settings); } }
public async Task Put_Return_CorrectViewModel(int id, string oldName, string newName) { // Arrange var scenarios = new List <NcScenario>(); var oldChannel = new NcChannel { Id = id, Name = oldName, }; var newChannel = new NcChannel { Id = id, Name = newName, }; var repository = new Mock <IChannelRepository>(); repository.Setup(x => x.FindById(id)).Returns(oldChannel); repository.Setup(x => x.UpdateAsync(It.IsAny <NcChannel>())).Returns(Task.CompletedTask); var expected = new ChannelViewModel { Id = id, Name = newName, Scenarios = mapper.MapEnumerable <ScenarioListDTO>(scenarios).ToList(), }.ToExpectedObject(); var controller = new ChannelsController( It.IsAny <ILogger <ChannelsController> >(), repository.Object, mapper, It.IsAny <IChannelManager>(), It.IsAny <ApplicationUserManager>()) .SetValidator(); // Act var controllerResult = await controller.Put(id, JsonConvert.SerializeObject(newChannel)); var actual = (controllerResult as OkObjectResult)?.Value; // Assert expected.ShouldEqual(actual); }
public void InsertAdTest() { var account = App.Config.GetDefaultAccount(); var context = account.GetContext(); var controller = new ChannelsController(); var channels = context.Channels.ToList(); var channel = channels.FirstOrDefault(c => c.State == ChannelState.Running && c.EncodingType != ChannelEncodingType.None); if (channel != null) { var settings = new Models.SlateSettings { Duration = 30, ShowSlate = true, CueId = (int)(DateTime.Now - new DateTime(1970, 1, 1)).TotalSeconds }; var operation = controller.AdMarker(account.AccountName, channel.Id.NimbusIdToRawGuid(), settings); } }
public async Task Delete_Call_RepositoryDelete() { // act var channel = new NcChannel(); var repository = new Mock <IChannelRepository>(); repository.Setup(x => x.DeleteAsync(It.IsAny <int>())).Returns(Task.CompletedTask); var controller = new ChannelsController(It.IsAny <ILogger <ChannelsController> >(), repository.Object, mapper, It.IsAny <ChannelManager>(), null) .SetValidator(); // arrange await controller.Delete(It.IsAny <int>()); // assert repository.VerifyAll(); }
public async Task Put_Call_RepositoryFindById() { // act var channel = new NcChannel(); var repository = new Mock <IChannelRepository>(); repository.Setup(x => x.FindById(It.IsAny <int>())).Returns(channel); var controller = new ChannelsController(It.IsAny <ILogger <ChannelsController> >(), repository.Object, mapper, It.IsAny <ChannelManager>(), null) .SetValidator(); // arrange await controller.Put(It.IsAny <int>(), It.IsAny <string>()); // assert repository.VerifyAll(); }
public void GetChannelById_ExistingChannel_ShouldReturn200OK_CorrectChannelData() { // Arrange -> create a few channels var dataLayerMock = new MessagesDataMock(); var channelsMock = dataLayerMock.Channels; channelsMock.Add(new Channel() { Id = 1, Name = "Channel #1" }); channelsMock.Add(new Channel() { Id = 2, Name = "Channel #2" }); channelsMock.Add(new Channel() { Id = 3, Name = "Channel #3" }); // Act -> Get channel by ID var channelsController = new ChannelsController(dataLayerMock); this.SetupControllerForTesting(channelsController, "channels"); var httpResponse = channelsController.GetChannelById(2) .ExecuteAsync(new CancellationToken()).Result; // Assert -> HTTP status code 200 (OK) + correct channel data Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); var channel2 = httpResponse.Content.ReadAsAsync<ChannelModel>().Result; Assert.AreEqual(2, channel2.Id); Assert.AreEqual("Channel #2", channel2.Name); }
public void GetChannelProgramsTest() { var account = App.Config.GetDefaultAccount(); var controller = new ChannelsController(); var context = account.GetContext(); Assert.IsNotNull(context); MediaChannel chlContent = null; foreach (var channel in context.Channels) { int programCount = channel.Programs.Count(); if (programCount > 0) { chlContent = controller.GetChannelById(account.AccountName, channel.Id.NimbusIdToRawGuid()); Assert.IsNotNull(chlContent, "Context not Accessible"); break; } } }
public async Task Load_Call_RepositoryGetAll() { // act var id = It.IsAny <int>(); var channel = new NcChannel(); var repository = new Mock <IChannelRepository>(); var controller = new ChannelsController( It.IsAny <ILogger <ChannelsController> >(), repository.Object, mapper, It.IsAny <IChannelManager>(), It.IsAny <ApplicationUserManager>()) .SetValidator(); // arrange await controller.Delete(id); // assert repository.Verify(x => x.DeleteAsync(id), Times.Once()); }
public async Task Post_Return_CorrectViewModel() { // Arrange int id = 20; string name = "Test"; var scenarios = new List <NcScenario>(); var channel = new NcChannel { Id = id, Name = name, }; var logger = new Mock <ILogger <ChannelsController> >(); var repository = new Mock <IChannelRepository>(); var manager = new Mock <IChannelManager>(); var expected = new ChannelViewModel { Id = id, Name = name, Scenarios = mapper.MapEnumerable <ScenarioListDTO>(scenarios).ToList(), }.ToExpectedObject(); var controller = new ChannelsController(logger.Object, repository.Object, mapper, manager.Object, It.IsAny <ApplicationUserManager>()) .SetValidator(); // Act var controllerResult = await controller.Post(JsonConvert.SerializeObject(channel)); // Assert var actual = (controllerResult as OkObjectResult)?.Value; expected.ShouldEqual(actual); }
public void ChannelCRUDTest() { var account = App.Config.Content.ContentProviders[0].MediaServicesSets[0].MediaServicesAccounts[0]; var controller = new ChannelsController(); var context = account.GetContext(); int chnlCount = context.Channels.Count(); var name = string.Format("New-Channel-{0}", DateTime.UtcNow.ToOADate().ToString().Replace(".", "-")); var settings = new Models.ChannelSettings { Name = name }; var operation = controller.Create(account.AccountName, settings); while (operation.State == OperationState.InProgress) { Thread.Sleep(10000); operation = context.Operations.GetOperation(operation.Id); } Assert.AreEqual(chnlCount + 1, context.Channels.Count()); var channel = context.Channels.ToList().First(c => c.Name == name); var range = new Models.IPRange { SubnetPrefixLength = 32, Address = "127.0.0.1" }; //update the channel. var updateSettings = new Models.ChannelUpdateSettings { IngestAllowList = new Models.IPRange[] { range }, PreviewAllowList = new Models.IPRange[] { range }, Description = "SomeDescription" }; operation = controller.Update(account.AccountName, channel.Id.NimbusIdToRawGuid(), updateSettings); while (operation.State == OperationState.InProgress) { Thread.Sleep(10000); operation = context.Operations.GetOperation(operation.Id); } // create new context to avoid cache issue. context = account.GetContext(); channel = context.Channels.Where(c => c.Id == channel.Id).FirstOrDefault(); Assert.IsNotNull(channel); // verify ingest. Assert.AreEqual(1, channel.Input.AccessControl.IPAllowList.Count); Assert.AreEqual("Range0", channel.Input.AccessControl.IPAllowList[0].Name); Assert.AreEqual(range.SubnetPrefixLength, channel.Input.AccessControl.IPAllowList[0].SubnetPrefixLength); Assert.AreEqual(range.Address, channel.Input.AccessControl.IPAllowList[0].Address); // verify preview. Assert.AreEqual(1, channel.Preview.AccessControl.IPAllowList.Count); Assert.AreEqual("Range0", channel.Preview.AccessControl.IPAllowList[0].Name); Assert.AreEqual(range.SubnetPrefixLength, channel.Preview.AccessControl.IPAllowList[0].SubnetPrefixLength); Assert.AreEqual(range.Address, channel.Preview.AccessControl.IPAllowList[0].Address); operation = controller.Delete(account.AccountName, channel.Id.NimbusIdToRawGuid()); while (operation.State == OperationState.InProgress) { Thread.Sleep(10000); operation = context.Operations.GetOperation(operation.Id); } Assert.AreEqual(chnlCount, context.Channels.Count()); }