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 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_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);
        }
Beispiel #5
0
        public void GetAllUsers()
        {
            usersController.ControllerContext = ContextMock.Build(1);
            var result = usersController.GetAllUsers().Result;

            result.Should().NotBeNull();
            result.Result.Should().BeOfType <OkObjectResult>();
            ((OkObjectResult)result.Result).Value.Should().BeOfType <List <UserDto> >();
            ((List <UserDto>)((OkObjectResult)result.Result).Value).Count.Should().BeGreaterThan(0);
        }
Beispiel #6
0
        public void GetUserById()
        {
            usersController.ControllerContext = ContextMock.Build(1);
            var result = usersController.GetUser(1).Result;

            result.Should().NotBeNull();
            result.Result.Should().BeOfType <OkObjectResult>();
            ((OkObjectResult)result.Result).Value.Should().BeOfType <UserDto>();
            ((UserDto)((OkObjectResult)result.Result).Value).Login.Should().Be("User1");
        }
        protected override void HandleReference_OneMany_RealSide_Checks(Order sourceRelated, PropertyAccessor sourceReference, Order cloneRelated, PropertyAccessor cloneReference)
        {
            Expect.Call(ContextMock.GetCloneFor <DomainObject> (sourceRelated)).Return(cloneRelated);

            MockRepository.ReplayAll();
            _strategy.HandleReference(sourceReference, cloneReference, ContextMock);
            MockRepository.VerifyAll();

            Assert.That(cloneReference.GetValueWithoutTypeCheck(), Is.SameAs(cloneRelated));
        }
        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);
        }
        public EmployeesServiceTests()
        {
            var services = new ServiceCollection();

            services.AddScoped <IUnitOfWork, UnitOfWork>();
            this._context = ContextMock.Seed();

            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new SettingAutomapper());
            });

            this._mapper = mappingConfig.CreateMapper();
            services.AddSingleton(_mapper);
        }
        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);
        }
Beispiel #12
0
        public void Register_WithDefaultProperties_UsesComponentPathAndPackageGuidValue()
        {
            var attribute    = new ProvideBindingPathAttribute();
            var expectedKeys = new Hashtable()
            {
                //Build the data for each reg key entry in the hash table.
                {
                    @"BindingPaths\".ToUpperInvariant() + ContextMock.GetType().GUID.ToString("B").ToUpperInvariant(),
                    new Hashtable()
                    {
                        { Path.GetDirectoryName(Assembly.GetExecutingAssembly().EscapedCodeBase).ToUpperInvariant(), "" }
                    }
                }
            };

            AttributeCommonTest.RegistrationTest(attribute, expectedKeys, new BaseRegistrationContextMock());
        }
        public void GetDropdown()
        {
            var examples = new List <ExampleEntity>
            {
                new ExampleEntity("Example 1"),
                new ExampleEntity("Example 2"),
                new ExampleEntity("Example 3"),
            };

            var mockSet = ContextMock.CreateMockForDbSet <ExampleEntity>()
                          .SetupForQueryOn(examples);

            var mockContext = ContextMock.CreateMockForDbContext(mockSet);

            var service = new ExampleEntityService(mockContext.Object, null);

            var result = service.GetDropdown();
        }
        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);
        }
Beispiel #15
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);
        }
        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);
        }
Beispiel #17
0
        public void SessionsCollectionIsUpdatedCorrectly()
        {
            var newOpenTime = new TimeSpan(10, 0, 0);

            //set up DbSet mocks
            SetUpDbSet(new List <Instrument>());

            SetUpDbSet(new List <ExchangeSession>());

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

            //remove one
            exchange.Sessions.Remove(exchange.Sessions.First());
            //change one
            exchange.Sessions.First().OpeningTime = newOpenTime;
            //add one
            exchange.Sessions.Add(new ExchangeSession {
                OpeningDay = DayOfTheWeek.Wednesday, OpeningTime = new TimeSpan(11, 0, 0), ClosingTime = new TimeSpan(15, 0, 0)
            });

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

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

            //verify update
            ContextMock.Verify(x => x.UpdateEntryValues(
                                   It.Is <ExchangeSession>(y => y.ID == 2),
                                   It.Is <ExchangeSession>(y => y.OpeningTime == newOpenTime)));

            //verify delete
            ContextMock.Verify(x => x.SetEntryState(
                                   It.Is <ExchangeSession>(y => y.ID == 1),
                                   It.Is <EntityState>(y => y == EntityState.Deleted)));

            //verify addition
            Assert.IsTrue(_data[0].Sessions.Any(x => x.OpeningDay == DayOfTheWeek.Wednesday && x.OpeningTime == new TimeSpan(11, 0, 0)));
        }
Beispiel #18
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;
        }
Beispiel #19
0
        public void Register_WithSubFolderSpecified_UsesPackageFolderTokenWithSubTokenAndPackageGuidValue()
        {
            var attribute = new ProvideBindingPathAttribute()
            {
                SubPath = "subFolder",
            };

            var expectedKeys = new Hashtable()
            {
                //Build the data for each reg key entry in the hash table.
                {
                    @"BindingPaths\".ToUpperInvariant() + ContextMock.GetType().GUID.ToString("B").ToUpperInvariant(),
                    new Hashtable()
                    {
                        { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().EscapedCodeBase), "subFolder").ToUpperInvariant(), "" }
                    }
                }
            };

            AttributeCommonTest.RegistrationTest(attribute, expectedKeys, new BaseRegistrationContextMock());
        }
Beispiel #20
0
        public void GetUserByLogin()
        {
            UserDto intput = new UserDto()
            {
                AppId        = 1,
                Login        = "******",
                PasswordHash = "098f6bcd4621d373cade4e832627b4f6",
                Permissions  = new List <string>()
                {
                    "User"
                }
            };

            usersController.ControllerContext = ContextMock.Build(1);

            var result = usersController.AddUser(intput).Result;

            result.Should().NotBeNull();
            //result.Should().BeOfType<OkObjectResult>();
            //((OkObjectResult)result.Result).Value.Should().BeOfType<UserDto>();
            //((UserDto)((OkObjectResult)result.Result).Value).Login.Should().Be("User1");
        }
        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);
        }
        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);
        }
 private void ThenActionsShouldNotBeExecuted()
 {
     ContextMock.Verify(c => c.Result1IsAsExpected(), Times.Never);
     ContextMock.Verify(c => c.Result2IsAsExpected(), Times.Never);
 }
 private void WhenActionShouldBeExecutedOnce()
 {
     ContextMock.Verify(c => c.SomethingIsDone(), Times.Once);
 }
 private void WhenActionShouldNotBeExecuted()
 {
     ContextMock.Verify(c => c.SomethingIsDone(), Times.Never);
 }
 private void AllThenActionsShouldBeExecutedOnce()
 {
     ContextMock.Verify(c => c.Result1IsAsExpected(), Times.Once);
     ContextMock.Verify(c => c.Result2IsAsExpected(), Times.Once);
 }
 protected void FirstGivenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.FirstFact()).Throws(exception);
 protected void SecondThenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.Result2IsAsExpected()).Throws(exception);
 protected void ExceptionCheckThrows(Exception exception) =>
 ContextMock.Setup(c => c.ExceptionIsThrown(It.IsAny <Result>())).Throws(exception);
 protected void WhenActionThrows(Exception exception) =>
 ContextMock.Setup(c => c.SomethingIsDone()).Throws(exception);