Пример #1
0
        public async Task Movie_Uses_Default_Url_When()
        {
            SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new EmbySettings
            {
                Enable  = true,
                Servers = new List <EmbyServers>
                {
                    new EmbyServers
                    {
                        ServerHostname = string.Empty,
                        ServerId       = "8"
                    }
                }
            });
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new EmbyContent
            {
                ProviderId = "123",
                EmbyId     = 1.ToString()
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.That(search.EmbyUrl, Is.EqualTo("https://app.emby.media/web/index.html#!/item?id=1&serverId=8"));
        }
        public async Task Movie_Has_Custom_Url_When_Specified_In_Settings()
        {
            SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings
            {
                Enable  = true,
                Servers = new List <JellyfinServers>
                {
                    new JellyfinServers
                    {
                        ServerHostname = "http://test.com/",
                        ServerId       = "8"
                    }
                }
            });
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new JellyfinContent
            {
                ProviderId = "123",
                JellyfinId = 1.ToString(),
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.That(search.JellyfinUrl, Is.EqualTo("http://test.com/web/index.html#!/details?id=1&serverId=8"));
        }
        public async Task Movie_Uses_Default_Url_When()
        {
            SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings
            {
                Enable  = true,
                Servers = new List <JellyfinServers>
                {
                    new JellyfinServers
                    {
                        Ip             = "8080",
                        Port           = 9090,
                        ServerHostname = string.Empty,
                        ServerId       = "8"
                    }
                }
            });
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new JellyfinContent
            {
                ProviderId = "123",
                JellyfinId = 1.ToString()
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
        }
        public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInJellyfin()
        {
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).Returns(Task.FromResult(default(JellyfinContent)));
            var search = new SearchMovieViewModel();
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.False(search.Available);
        }
        public async Task Movie_Uses_Default_Url_When()
        {
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new JellyfinContent
            {
                TheMovieDbId = "123",
                JellyfinId   = 1.ToString()
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
        }
Пример #6
0
        public async Task Movie_ShouldBe_Available_WhenFoundInEmby()
        {
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new EmbyContent
            {
                TheMovieDbId = "123",
                Quality      = "1"
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.True(search.Available);
        }
        public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin()
        {
            SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings());
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new JellyfinContent
            {
                ProviderId = "123"
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.True(search.Available);
        }
        public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin_4K()
        {
            FeatureMock.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(true);
            ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny <string>())).ReturnsAsync(new JellyfinContent
            {
                TheMovieDbId = "123",
                Has4K        = true
            });
            var search = new SearchMovieViewModel()
            {
                TheMovieDbId = "123",
            };
            var result = await Rule.Execute(search);

            Assert.True(result.Success);
            Assert.False(search.Available);
            Assert.True(search.Available4K);
        }
Пример #9
0
        public void InstrumentsWithExchangeAsSessionSourceHaveTheirSessionsUpdatedWhenExchangeIsUpdated()
        {
            //needed to simulate the update of the session
            ContextMock
            .Setup(x => x.UpdateEntryValues(It.IsAny <ExchangeSession>(), It.IsAny <ExchangeSession>()))
            .Callback <object, object>((oldSession, newSession) =>
                                       ((ExchangeSession)oldSession).OpeningTime = ((ExchangeSession)newSession).OpeningTime);

            //set up DbSet mocks
            var instrumentSessions = new List <InstrumentSession>
            {
                new InstrumentSession {
                    OpeningTime = new TimeSpan(9, 0, 0)
                }
            };
            var instrument = new Instrument {
                SessionsSource = SessionsSource.Exchange, ExchangeID = 1, Sessions = instrumentSessions
            };
            var instrumentData = new List <Instrument> {
                instrument
            };

            SetUpDbSet(instrumentData);

            SetUpDbSet(new List <ExchangeSession>());

            SetUpDbSet(new List <InstrumentSession>());

            //Update session
            var exchange = (Exchange)_data[0].Clone(); //have to clone it, because the original is the one in the mocked context

            exchange.Sessions.First().OpeningTime = new TimeSpan(10, 0, 0);

            var response = Browser.Put("/exchanges", with =>
            {
                with.HttpRequest();
                with.JsonBody(exchange);
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            //Now the instrument should have the updated session times
            Assert.AreEqual(new TimeSpan(10, 0, 0), instrument.Sessions.First().OpeningTime);
        }
Пример #10
0
        public async Task ExistingRequestRule_Movie_Has_Been_Requested_With_TheMovieDBId()
        {
            ContextMock.Setup(x => x.GetAll()).Returns(new List <MovieRequests>
            {
                new MovieRequests
                {
                    TheMovieDbId = 1,
                    RequestType  = RequestType.Movie
                }
            }.AsQueryable().BuildMock().Object);
            var o = new MovieRequests
            {
                TheMovieDbId = 1,
            };
            var result = await Rule.Execute(o);

            Assert.That(result.Success, Is.False);
            Assert.That(result.Message, Is.Not.Empty);
        }
Пример #11
0
        public void Given_City_When_GetForecast_Then_ForecastModelIsReturned()
        {
            // Arrange
            var country = new Country
            {
                namecity = "Stockholm",
                id       = 1
            };

            var countries = (new Country[] { country }).AsQueryable();

            var mockSet = new Mock <DbSet <Country> >();

            mockSet.As <IQueryable <Country> >().Setup(s => s.Expression).Returns(countries.Expression);
            mockSet.As <IQueryable <Country> >().Setup(s => s.Provider).Returns(countries.Provider);

            ContextMock.Setup(c => c.Countries).Returns(mockSet.Object);

            // Act
            var result = Controller.Get(country.namecity).Result;
        }
Пример #12
0
        public async Task ExistingRequestRule_Movie_HasAlready4K_Request()
        {
            ContextMock.Setup(x => x.GetAll()).Returns(new List <MovieRequests>
            {
                new MovieRequests
                {
                    TheMovieDbId = 2,
                    ImdbId       = "2",
                    RequestType  = RequestType.Movie,
                    Is4kRequest  = true
                }
            }.AsQueryable().BuildMock().Object);
            var o = new MovieRequests
            {
                TheMovieDbId = 2,
                ImdbId       = "1",
                Has4KRequest = true
            };
            var result = await Rule.Execute(o);

            Assert.That(result.Success, Is.False);
            Assert.That(result.Message, Is.Not.Empty);
        }
Пример #13
0
        public async Task ExistingRequestRule_Movie_4K_Request_FeatureNotEnabled()
        {
            FeatureService.Setup(x => x.FeatureEnabled(FeatureNames.Movie4KRequests)).ReturnsAsync(false);
            ContextMock.Setup(x => x.GetAll()).Returns(new List <MovieRequests>
            {
                new MovieRequests
                {
                    TheMovieDbId = 2,
                    ImdbId       = "2",
                    RequestType  = RequestType.Movie,
                    Is4kRequest  = false
                }
            }.AsQueryable().BuildMock().Object);
            var o = new MovieRequests
            {
                TheMovieDbId = 2,
                ImdbId       = "1",
                Is4kRequest  = true
            };
            var result = await Rule.Execute(o);

            Assert.That(result.Success, Is.False);
            Assert.That(result.Message, Is.Not.Null);
        }
Пример #14
0
 protected void FirstGivenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.FirstFact()).Throws(exception);
Пример #15
0
 protected void SecondThenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.Result2IsAsExpected()).Throws(exception);
Пример #16
0
 protected void ExceptionCheckThrows(Exception exception) =>
 ContextMock.Setup(c => c.ExceptionIsThrown(It.IsAny <Result>())).Throws(exception);
Пример #17
0
 protected void WhenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.SomethingIsDone()).Throws(exception);