public void PostBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithDateCreatedAndStatusNew()
        {
            // Arrange
            var repo = new RepositoryMock<Bug>();
            repo.IsSaveCalled = false;
            repo.Entities = new List<Bug>();
            var newBug = new Bug()
            {
                Text = "Test bug"
            };
            var controller = new BugsController(repo);
            this.SetupController(controller, "bugs");

            // Act
            var httpResponse = controller.PostBug(newBug).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);

            var bugFromService = httpResponse.Content.ReadAsAsync<Bug>().Result;
            Assert.AreEqual(bugFromService.Text, newBug.Text);
            Assert.AreEqual(bugFromService.Status, BugStatus.New);
            Assert.IsNotNull(bugFromService.DateCreated);

            // Assert the repository values are correct
            Assert.AreEqual(repo.Entities.Count, 1);
            var bugInRepo = repo.Entities.First();
            Assert.AreEqual(newBug.Text, bugInRepo.Text);
            Assert.IsNotNull(bugInRepo.DateCreated);
            Assert.AreEqual(BugStatus.New, bugInRepo.Status);
            Assert.IsTrue(repo.IsSaveCalled);
        }
    public void GetAll_WhenValid_ShouldReturnBugsCollection()
    {
        // Arrange
        var repo = new RepositoryMock<Bug>();

        var bugs = new List<Bug>()
        {
            new Bug()
            {
                Text = "Test bug #1"
            },
            new Bug()
            {
                Text = "Test bug #2"
            },
            new Bug()
            {
                Text = "Test bug #3"
            }
        };            
            
        repo.Entities = bugs;

        var controller = new BugsController(repo);

        // Act
        var result = controller.GetAll();

        // Assert
        CollectionAssert.AreEquivalent(bugs, result.ToList<Bug>());
    }
 public void GetCustomerStatisticsTest()
 {
     IRepository<Measurement> measurerepo = new RepositoryMock<Measurement>();
     StatisticsService target = new StatisticsService(measurerepo); 
     Customer customer = null;
     DateTime StartDate = new DateTime();
     DateTime EndDate = new DateTime();            
     target.GetCustomerStatistics(customer, StartDate, EndDate);
 }
Example #4
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_siteSettings = _container.SettingsService.GetSiteSettings();

			_pluginFactory = _container.PluginFactory;
			_repository = _container.Repository;
		}
Example #5
0
        public void Constructor_Should_Set_Cacheable_To_True()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            ApplicationSettings appSettings = new ApplicationSettings();

            TextPluginStub plugin = new TextPluginStub();

            // Act + Assert
            Assert.That(plugin.IsCacheable, Is.True);
        }
Example #6
0
		public void Setup()
		{
			_container = new MocksAndStubsContainer();

			_applicationSettings = _container.ApplicationSettings;
			_userContext = _container.UserContext;
			_userService = _container.UserService;
			_repositoryMock = _container.Repository;
			_pageService = _container.PageService;

			_pagesController = new PagesController(_pageService, _applicationSettings, _userService, _userContext);
		}
        public void Setup()
        {
            _container = new MocksAndStubsContainer();

            _applicationSettings = _container.ApplicationSettings;
            _applicationSettings.AttachmentsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "attachments");
            _context = _container.UserContext;
            _repository = _container.Repository;
            _settingsService = _container.SettingsService;
            _userService = new FormsAuthUserService(_applicationSettings, _repository);
            _configReaderWriter = new ConfigReaderWriterStub();

            _upgradeController = new UpgradeController(_applicationSettings, _repository, _userService, _context, _settingsService, _configReaderWriter);
        }
        public void DeleteNonExistingNewsItemByID_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            // Act
            var resultPostAction = controller.DeleteNewsItem(5).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, resultPostAction.StatusCode);
        }
        public void CreateNewsItemWithCorrectData()
        {
            var repo = new RepositoryMock<News>();
            repo.IsSaveCalled = false;
            repo.Entities = new Dictionary<object, News>();
            var news = new News()
            {
                Id = 1,
                AuthorId = "valid",
                Title = "valid",
                Content = "valid",
                PublishDate = DateTime.Now
            };

            var controller = new NewsController(repo);
            this.SetupController(controller, "news");

            // Act
            var httpResponse = controller.CreateNews(new NewsBindingModel()
            {
                Id = news.Id,
                AuthorId = news.AuthorId,
                Title = news.Title,
                Content = news.Content,
                PublishDate = news.PublishDate
            }).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);

            var newsFromService = httpResponse.Content.ReadAsAsync<News>().Result;
            Assert.AreEqual(newsFromService.Title, news.Title);
            Assert.AreEqual(newsFromService.AuthorId, news.AuthorId);
            Assert.AreEqual(newsFromService.Content, news.Content);
            Assert.AreEqual(newsFromService.Id, news.Id);
            Assert.IsNotNull(newsFromService.PublishDate);

            Assert.AreEqual(repo.Entities.Count, 1);
            var newsInRepo = repo.Entities.First().Value;
            Assert.AreEqual(news.Title, newsInRepo.Title);
            Assert.AreEqual(news.Id, newsInRepo.Id);
            Assert.AreEqual(news.Content, newsInRepo.Content);
            Assert.AreEqual(news.AuthorId, newsInRepo.AuthorId);
            Assert.IsNotNull(newsInRepo.PublishDate);
            Assert.IsTrue(repo.IsSaveCalled);
        }
        public void ListAllNewsItemsCorrectly()
        {
            var repo = new RepositoryMock<News>();

            var news = new Dictionary<object, News>();

            news.Add(1, new News()
            {
                Id = 1,
                AuthorId = "test",
                Content = "News1 Content",
                Title = "News1 Title",
                PublishDate = DateTime.Now
            });

            news.Add(2, new News()
            {
                Id = 2,
                AuthorId = "test",
                Content = "News2 Content",
                Title = "News2 Title",
                PublishDate = DateTime.Now
            });

            news.Add(3, new News()
            {
                Id = 3,
                AuthorId = "test",
                Content = "News3 Content",
                Title = "News3 Title",
                PublishDate = DateTime.Now
            });

            repo.Entities = news;

            var controller = new NewsController(repo);

            var result = controller.GetAllNews().ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);

            var theNews = JsonConvert.DeserializeObject<Dictionary<object, News>>(result.Content.ReadAsStringAsync().Result);

            // Assert
            CollectionAssert.AreEquivalent(news, theNews);
        }
        public void DeleteNewsItemByID_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            // Act
            var resultPostAction = controller.DeleteNewsItem(news[2].Id).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, resultPostAction.StatusCode);

            var content = resultPostAction.Content.ReadAsStringAsync().Result;
            var resultNews = JsonConvert.DeserializeObject<NewsItem>(content);
        }
        public void AddPage_Should_Clear_List_And_PageSummary_Caches()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock pageModelCache = new CacheMock();
            CacheMock listCache = new CacheMock();

            PageService pageService = CreatePageService(pageModelCache, listCache, repository);
            PageViewModel expectedModel = CreatePageViewModel();
            AddPageCacheItem(pageModelCache, "key", expectedModel);
            AddListCacheItem(listCache, "key", new List<string>() { "tag1", "tag2" });

            // Act
            pageService.AddPage(new PageViewModel() { Title = "totoro" });

            // Assert
            Assert.That(pageModelCache.CacheItems.Count, Is.EqualTo(0));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
Example #13
0
        public async Task GetHighlightsAsync_NoHighlights()
        {
            List <Highlight> highlights = new List <Highlight>();

            RepositoryMock.Setup(
                repository => repository.GetHighlightsAsync())
            .Returns(
                Task.FromResult(highlights)
                );

            List <Highlight> retrievedHighlights = await Service.GetHighlightsAsync();

            Assert.DoesNotThrow(() => {
                RepositoryMock.Verify(repository => repository.GetHighlightsAsync(), Times.Once);
            });

            Assert.AreEqual(highlights, retrievedHighlights);
            Assert.AreEqual(0, retrievedHighlights.Count);
        }
Example #14
0
		public void GetById_Should_Load_From_Cache_When_PageSummary_Exists_In_Cache()
		{
			// Arrange
			RepositoryMock repository = new RepositoryMock();
			CacheMock pageModelCache = new CacheMock();
			PageService pageService = CreatePageService(pageModelCache, null, repository);

			PageViewModel expectedModel = CreatePageViewModel();
			string cacheKey = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);
			pageModelCache.Add(cacheKey, expectedModel, new CacheItemPolicy());

			// Act
			PageViewModel actualModel = pageService.GetById(1);

			// Assert
			Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
			Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
			Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
		}
Example #15
0
        public async Task GetCallToActionOptionsFromTypeAsync_NoOptionsFound()
        {
            // Arrange
            RepositoryMock
            .Setup(repository => repository.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>()))
            .ReturnsAsync(Enumerable.Empty <CallToActionOption>());

            // Act
            IEnumerable <CallToActionOption> actualOptions =
                await Service.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>());

            Action act = () =>
                         RepositoryMock.Verify(repository => repository.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>()),
                                               Times.Once());

            // Assert
            actualOptions.Should()
            .BeEmpty();
            act.Should().NotThrow();
        }
Example #16
0
        public UserServiceSetup()
        {
            _userRepoMock      = new RepositoryMock <User>(GetUsersTestData().ToList());
            _userManagerMock   = new Mock <FakeUserManager>();
            _signInManagerMock = new Mock <FakeSigInManager>();
            _authService       = new Mock <IAuthenticationService>();
            _unitOfWorkMock    = new Mock <IUnitOfWork>();
            _fileService       = new Mock <IFileService>();
            _mapper            = new Mock <IMapper>();
            _env            = new Mock <IHostingEnvironment>();
            _emailService   = new Mock <IEmailService>();
            _unitOfWorkMock = new Mock <IUnitOfWork>();
            var _emailSettings = Options.Create(new EmailSettings());

            _unitOfWorkMock.Setup(u => u.Repository <User>()).Returns(_userRepoMock.Repository.Object);
            _unitOfWorkMock.Setup(u => u.SaveChangesAsync()).Verifiable();
            _unitOfWorkMock.Setup(u => u.Repository <User>()).Returns(_userRepoMock.Repository.Object);
            _userService = new UserService(_userManagerMock.Object, _signInManagerMock.Object, _authService.Object, _mapper.Object, _fileService.Object,
                                           _unitOfWorkMock.Object, _emailService.Object, _env.Object, _emailSettings);
        }
        public void GetById_Should_Load_From_Cache_When_PageSummary_Exists_In_Cache()
        {
            // Arrange
            RepositoryMock repository     = new RepositoryMock();
            CacheMock      pageModelCache = new CacheMock();
            PageService    pageService    = CreatePageService(pageModelCache, null, repository);

            PageViewModel expectedModel = CreatePageViewModel();
            string        cacheKey      = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);

            pageModelCache.Add(cacheKey, expectedModel, new CacheItemPolicy());

            // Act
            PageViewModel actualModel = pageService.GetById(1);

            // Assert
            Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
            Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
            Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
        }
        public void GetAll_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            // Act
            var httpResponse = controller.GetNewsItems().ExecuteAsync(new CancellationToken()).Result;
            var content = httpResponse.Content.ReadAsStringAsync().Result;
            var resultNews = JsonConvert.DeserializeObject<List<NewsItem>>(content);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);

            CollectionAssert.AreEqual(news, resultNews.ToArray<NewsItem>());
            Assert.AreEqual(3, news.Count);
        }
        public void FindHomePage_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Title = "1", Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);

            CacheMock   pageCache   = new CacheMock();
            PageService pageService = CreatePageService(pageCache, null, repository);

            // Act
            pageService.FindHomePage();

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(pageCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(CacheKeys.HomepageKey()));
        }
        public void FindHomePage_Should_Load_From_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock      modelCache = new CacheMock();

            PageService   pageService   = CreatePageService(modelCache, null, repository);
            PageViewModel expectedModel = CreatePageViewModel();

            expectedModel.RawTags = "homepage";
            modelCache.Add(CacheKeys.HomepageKey(), expectedModel, new CacheItemPolicy());

            // Act
            PageViewModel actualModel = pageService.FindHomePage();

            // Assert
            Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
            Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
            Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
        }
        public void AllTags_Should_Load_From_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock      listCache  = new CacheMock();

            PageService   pageService  = CreatePageService(null, listCache, repository);
            List <string> expectedTags = new List <string>()
            {
                "tag1", "tag2", "tag3"
            };

            AddListCacheItem(listCache, CacheKeys.AllTags(), expectedTags);

            // Act
            IEnumerable <string> actualTags = pageService.AllTags().Select(x => x.Name);

            // Assert
            Assert.That(actualTags, Is.SubsetOf(expectedTags));
        }
        private void InitializeRepository(IList <OrderModel> orderModels = null, IList <ProductModel> productModels = null)
        {
            if (orderModels == null)
            {
                orderModels = new OrderModel[0];
            }
            if (productModels == null)
            {
                productModels = new ProductModel[0];
            }
            Task <IList <OrderModel> >   result        = Task.FromResult(orderModels);
            Task <IList <ProductModel> > productResult = Task.FromResult(productModels);

            RepositoryMock
            .Setup(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()))
            .Returns(result);
            RepositoryMock
            .Setup(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()))
            .Returns(productResult);
        }
Example #23
0
        public void Should_Release_Main_Lock_Before_Secondary_Ones()
        {
            bool mainReleased = false;

            //set the bool to true on release
            RepositoryMock.Setup(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId))
            .Callback(() => mainReleased = true);

            //verify flag was switched
            RepositoryMock.Setup(rep => rep.ReleaseLock(It.IsAny <LockItem>()))
            .Callback(() => Assert.IsTrue(mainReleased));

            //make sure putting the guard into a using construct eventually releases the lock
            using (var grd = new ResourceLockGuard(Lock, RepositoryMock.Object)
            {
                SecondaryLocks = SecondaryLocks
            })
            {
            }
        }
Example #24
0
        public void Settings_Should_Create_Instance_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(actualPluginSettings.Values.Count(), Is.EqualTo(0));
        }
        public void AllPagesCreatedBy_Should_Add_To_Cache_When_Cache_Is_Empty()
        {
            // Arrange
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");

            RepositoryMock repository = new RepositoryMock();
            repository.AddNewPage(new Page() { Title = "1" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "2" }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page() { Title = "3" }, "text", "editor", DateTime.UtcNow);

            CacheMock listCache = new CacheMock();
            PageService pageService = CreatePageService(null, listCache, repository);

            // Act
            pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.FirstOrDefault().Key, Is.EqualTo(adminCacheKey));
        }
        public async Task GetInstitutionByInstitutionIdentityId_NoIdentityId()
        {
            // Arrange
            RepositoryMock
            .Setup(repository => repository.GetInstitutionByInstitutionIdentityId(It.IsAny <string>()))
            .ReturnsAsync((Institution)null);

            // Act
            Institution actualInstitution = await Service.GetInstitutionByInstitutionIdentityId(string.Empty);

            Action act = () =>
                         RepositoryMock.Verify(repository => repository.GetInstitutionByInstitutionIdentityId(string.Empty),
                                               Times.Once);

            // Assert
            actualInstitution.Should()
            .BeNull();
            act.Should()
            .NotThrow();
        }
        public async Task ShouldFetchWorkItemsAndWorkItemTypes()
        {
            var workitems = Builder <WorkItem> .CreateListOfSize(5)
                            .TheFirst(3)
                            .With(w => w.Fields, new Dictionary <string, string> {
                { "System.WorkItemType", "Foo" }
            })
                            .TheRest()
                            .With(w => w.Fields, new Dictionary <string, string>())
                            .Build();

            var organization = Builder <OrganizationViewModel> .CreateNew()
                               .Build();

            var references = workitems.Select(w => new WorkItemReference(w.Id));
            var ids        = workitems.Select(w => w.Id).ToArray();

            _clientMock.Setup(c => c.ExecuteFlatQueryAsync(It.IsAny <string>(), default(CancellationToken)))
            .ReturnsAsync(new FlatWorkItemsQueryResult
            {
                WorkItems = references
            })
            .Verifiable();
            _clientMock.Setup(c => c.GetWorkItemsAsync(ids, null, It.IsAny <string[]>(), default(CancellationToken)))
            .ReturnsAsync(workitems)
            .Verifiable();

            RepositoryMock.Setup(r => r.GetByFilteredArrayAsync <Ether.Vsts.Dto.WorkItem>("Fields.v", It.IsAny <string[]>()))
            .ReturnsAsync(workitems.Select(w => new Ether.Vsts.Dto.WorkItem
            {
                WorkItemId = w.Id
            }));

            var result = await _handler.Handle(new FetchWorkItemsOtherThanBugsAndTasks(organization.Id));

            result.Should().HaveCountLessOrEqualTo(workitems.Count);
            result.Should().OnlyContain(i => workitems.Any(w => w.Id == i));

            _clientFactoryMock.Verify();
            _clientMock.Verify();
        }
Example #28
0
        public async Task ShouldHandlePullRequestCompletedInFuture()
        {
            var start  = DateTime.Now.AddDays(-11);
            var end    = DateTime.Now;
            var member = Builder <TeamMemberViewModel> .CreateNew()
                         .Build();

            var memberIds    = new[] { member.Id };
            var repositories = new[] { Guid.NewGuid() };
            var profile      = Builder <ProfileViewModel> .CreateNew()
                               .With(p => p.Members      = new[] { member.Id })
                               .With(p => p.Repositories = repositories)
                               .Build();

            var pullRequest = GetCompletedPullRequest(member.Id, repositories[0], end.AddHours(5), end.AddHours(5), createdInThePast: true);

            SetupGetProfile(profile);
            SetupGetTeamMember(new[] { member });
            SetupGetPullRequests(new[] { pullRequest });

            var command = new GeneratePullRequestsReport {
                Profile = Guid.NewGuid(), Start = start, End = end
            };

            await InvokeAndVerify <PullRequestsReport>(command, (report, reportId) =>
            {
                report.Should().NotBeNull();
                var firstMemberReport = report.IndividualReports.First();

                firstMemberReport.Created.Should().Be(1);
                firstMemberReport.Active.Should().Be(0);
                firstMemberReport.Completed.Should().Be(0);
                firstMemberReport.Abandoned.Should().Be(0);
                firstMemberReport.TotalIterations.Should().Be(1);
                firstMemberReport.TotalComments.Should().Be(2);
                firstMemberReport.AveragePRLifespan.Should().Be(TimeSpan.Zero);
            });

            DataSourceMock.VerifyAll();
            RepositoryMock.Verify();
        }
        public void get_all_retrieves_entity_on_provided_scheduler()
        {
            var scheduler  = new TestScheduler();
            var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose);
            var sut        = new AsyncRepositoryBuilder()
                             .WithDataStoreScheduler(scheduler)
                             .WithRepository(repository)
                             .Build();

            sut
            .GetAll()
            .Subscribe();

            repository
            .Verify(x => x.GetAll())
            .WasNotCalled();
            scheduler.AdvanceMinimal();
            repository
            .Verify(x => x.GetAll())
            .WasCalledExactlyOnce();
        }
        public void save_all_saves_entities_on_provided_scheduler()
        {
            var scheduler  = new TestScheduler();
            var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose);
            var sut        = new AsyncRepositoryBuilder()
                             .WithDataStoreScheduler(scheduler)
                             .WithRepository(repository)
                             .Build();

            sut
            .SaveAll(new[] { new TestEntity() })
            .Subscribe();

            repository
            .Verify(x => x.SaveAll(It.IsAny <IEnumerable <TestEntity> >()))
            .WasNotCalled();
            scheduler.AdvanceMinimal();
            repository
            .Verify(x => x.SaveAll(It.IsAny <IEnumerable <TestEntity> >()))
            .WasCalledExactlyOnce();
        }
Example #31
0
        public async Task ShouldReturnEmptyReportIfNoMembers()
        {
            var members = Enumerable.Empty <TeamMemberViewModel>();
            var profile = Builder <ProfileViewModel> .CreateNew()
                          .With(p => p.Members      = new Guid[0])
                          .With(p => p.Repositories = new Guid[0])
                          .Build();

            SetupGetProfile(profile);
            SetupGetTeamMember(members);
            SetupGetPullRequests(Enumerable.Empty <PullRequestViewModel>());

            await InvokeAndVerify <PullRequestsReport>(Command, (report, reportId) =>
            {
                report.Should().NotBeNull();
                report.Id.Should().Be(reportId);
                report.IndividualReports.Should().BeEmpty();
            });

            RepositoryMock.Verify();
        }
Example #32
0
        public void Settings_Should_Save_To_Repository_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            TextPluginStub plugin = new TextPluginStub();

            plugin.PluginCache = pluginCacheMock.Object;
            plugin.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = plugin.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            Assert.That(repository.TextPlugins.Count, Is.EqualTo(1));
            Assert.That(repository.TextPlugins.FirstOrDefault(), Is.EqualTo(plugin));
        }
Example #33
0
        public void Settings_Should_Call_OnInitializeSettings_When_Repository_Has_No_Settings()
        {
            // Arrange
            CacheMock           cache           = new CacheMock();
            ApplicationSettings appSettings     = new ApplicationSettings();
            Mock <IPluginCache> pluginCacheMock = new Mock <IPluginCache>();
            RepositoryMock      repository      = new RepositoryMock();

            Mock <TextPluginStub> pluginMock = new Mock <TextPluginStub>();

            pluginMock.Setup(x => x.Id).Returns("SomeId");
            pluginMock.Object.PluginCache = pluginCacheMock.Object;
            pluginMock.Object.Repository  = repository;

            // Act
            PluginSettings actualPluginSettings = pluginMock.Object.Settings;

            // Assert
            Assert.That(actualPluginSettings, Is.Not.Null);
            pluginMock.Verify(x => x.OnInitializeSettings(It.IsAny <PluginSettings>()), Times.Once);
        }
        public void VmShouldSaveAndRestoreStateHasChangesTrue()
        {
            var models = new List <OrderModel> {
                new OrderModel()
            };

            InitializeRepository(models);
            var viewModel = GetViewModel <OrderWorkspaceViewModel>();

            Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(models));
            RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once);

            RepositoryMock
            .Setup(repository => repository.GetProductsByOrderAsync(models[0].Id, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <IList <OrderProductModel> >(Empty.Array <OrderProductModel>()));
            MessagePresenterMock
            .Setup(
                box =>
                box.ShowAsync(It.IsAny <string>(), It.IsAny <string>(), MessageButton.YesNo, MessageImage.Question,
                              It.IsAny <MessageResult>(), It.IsAny <IDataContext>()))
            .Returns(Task.FromResult(MessageResult.Yes));
            viewModel.GridViewModel.SelectedItem = models[0];

            viewModel.RemoveOrderCommand.Execute(null);
            Assert.IsTrue(viewModel.HasChanges);
            Assert.AreEqual(viewModel.GridViewModel.OriginalItemsSource.Count, 0);

            var state = new DataContext();

            viewModel.SaveState(state);
            state = UpdateState(state);

            RepositoryMock.ResetCalls();
            viewModel = GetViewModel <OrderWorkspaceViewModel>();
            viewModel.LoadState(state);

            Assert.IsTrue(viewModel.HasChanges);
            RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once);
            Assert.AreEqual(viewModel.GridViewModel.OriginalItemsSource.Count, 0);
        }
        public void UpdatePage_Should_Clear_List_Cache_And_PageSummary_Cache()
        {
            // Arrange
            RepositoryMock repository = new RepositoryMock();

            repository.AddNewPage(new Page()
            {
                Tags = "homepage"
            }, "text", "admin", DateTime.UtcNow);
            repository.AddNewPage(new Page()
            {
                Tags = "tag2"
            }, "text", "admin", DateTime.UtcNow);

            CacheMock   pageCache   = new CacheMock();
            CacheMock   listCache   = new CacheMock();
            PageService pageService = CreatePageService(pageCache, listCache, repository);

            PageViewModel homepageModel = CreatePageViewModel();

            homepageModel.Id = 1;
            PageViewModel page2Model = CreatePageViewModel();

            page2Model.Id = 2;

            AddPageCacheItem(pageCache, CacheKeys.HomepageKey(), homepageModel);
            pageCache.Add(CacheKeys.PageViewModelKey(2, 0), page2Model, new CacheItemPolicy());
            AddListCacheItem(listCache, CacheKeys.AllTags(), new List <string>()
            {
                "tag1", "tag2"
            });

            // Act
            pageService.UpdatePage(page2Model);

            // Assert
            Assert.That(pageCache.CacheItems.Count, Is.EqualTo(1));
            Assert.That(listCache.CacheItems.Count, Is.EqualTo(0));
        }
Example #36
0
        public void CanCreateInstance()
        {
            var diff           = new DiffMock(null, null);
            var oldCommit      = Observable.Return((Variant <Commit, DiffTargets>?)null).Concat(Observable.Never <Variant <Commit, DiffTargets>?>());
            var newCommit      = Observable.Return((Variant <Commit, DiffTargets>?)null).Concat(Observable.Never <Variant <Commit, DiffTargets>?>());
            var compareOptions = Observable.Return(new CompareOptions()).Concat(Observable.Never <CompareOptions>());
            var repo           = new RepositoryMock(new List <CommitMock>(), new BranchCollectionMock(new List <BranchMock>()), null, diff);
            var repoObservable = Observable.Return(repo).Concat(Observable.Never <IRepositoryWrapper>());
            var input          = Observable
                                 .CombineLatest(oldCommit, newCommit, compareOptions, repoObservable, (o, n, c, r) => new DiffViewModelInput(r, o, n, c));

            var vm = new DiffViewModel(new TestSchedulers(), input);
            Variant <List <TreeEntryChanges>, Unexpected>?value = null;

            using var subscription = vm.TreeDiff.Subscribe(treeDiff => value = treeDiff);
            if (value is null)
            {
                throw new Exception("Value was not set.");
            }
            Assert.IsTrue(value.Is <Unexpected>());
            Assert.AreEqual(DiffViewModel.NoCommitSelectedMessage, value.Get <Unexpected>().Message);
        }
        public async Task GetInstitutionsAsync_GoodFlow(
            [InstitutionDataSource(30)] IEnumerable <Institution> institutions)
        {
            // Arrange
            RepositoryMock
            .Setup(repository => repository.GetInstitutionsAsync())
            .ReturnsAsync(institutions);

            // Act
            IEnumerable <Institution> actualInstitutions = await Service.GetInstitutionsAsync();

            Action act = () => RepositoryMock.Verify(repository => repository.GetInstitutionsAsync(), Times.Once);

            // Assert
            act.Should()
            .NotThrow();
            actualInstitutions.Should()
            .Contain(institutions);
            actualInstitutions.Count()
            .Should()
            .Be(30);
        }
        public void AllPagesCreatedBy_Should_Load_From_Cache()
        {
            string adminCacheKey = CacheKeys.AllPagesCreatedByKey("admin");
            string editorCacheKey = CacheKeys.AllPagesCreatedByKey("editor");

            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock listCache = new CacheMock();

            PageService pageService = CreatePageService(null, listCache, repository);
            PageViewModel adminModel = CreatePageViewModel();
            PageViewModel editorModel = CreatePageViewModel("editor");
            listCache.Add(CacheKeys.AllPagesCreatedByKey("admin"), new List<PageViewModel>() { adminModel }, new CacheItemPolicy());
            listCache.Add(CacheKeys.AllPagesCreatedByKey("editor"), new List<PageViewModel>() { editorModel }, new CacheItemPolicy());

            // Act
            IEnumerable<PageViewModel> actualList = pageService.AllPagesCreatedBy("admin");

            // Assert
            Assert.That(actualList, Contains.Item(adminModel));
            Assert.That(actualList, Is.Not.Contains(editorModel));
        }
        public async Task GetDataSourceByName_GoodFlow([DataSourceModelDataSource(1)] DataSource dataSource)
        {
            // Arrange
            RepositoryMock.Setup(repository => repository.GetDataSourceByName(It.IsAny <string>()))
            .ReturnsAsync(dataSource);

            // Act
            DataSource actualDataSource = await Service.GetDataSourceByName(It.IsAny <string>());

            Action act = () =>
                         RepositoryMock.Verify(repository => repository.GetDataSourceByName(It.IsAny <string>()), Times.Once);

            // Assert
            act.Should()
            .NotThrow();

            actualDataSource.Should()
            .NotBeNull();

            actualDataSource.Should()
            .Be(dataSource);
        }
        public void EditCmdShouldUseCommandParameterToShowOrderEditorViewModel()
        {
            var items = new List <OrderModel>
            {
                new OrderModel
                {
                    Id = Guid.NewGuid()
                }
            };
            bool isInitialized = false;
            IList <OrderProductModel> links = new List <OrderProductModel> {
                new OrderProductModel()
            };

            RepositoryMock
            .Setup(repository => repository.GetProductsByOrderAsync(items[0].Id, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(links));
            var wrapper = SetupEditableWrapper(false, vm =>
            {
                var editorViewModel = (OrderEditorViewModel)vm;
                editorViewModel.EntityInitialized += (model, args) =>
                {
                    Assert.AreEqual(args.OriginalEntity, items[0]);
                    Assert.IsTrue(editorViewModel.OldLinks.SequenceEqual(links));
                    isInitialized = true;
                };
            });

            InitializeRepository(items);
            var viewModel = GetViewModel <OrderWorkspaceViewModel>();

            viewModel.GridViewModel.SelectedItem = null;

            viewModel.EditOrderCommand.Execute(items[0]);
            ViewModelPresenterMock.Verify(model => model.ShowAsync(wrapper.Object, It.IsAny <IDataContext>()), Times.Once);
            RepositoryMock.Verify(
                repository => repository.GetProductsByOrderAsync(items[0].Id, It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsTrue(isInitialized);
        }
        public void SaveCmdShouldSaveChangesToRepository()
        {
            RepositoryMock
            .Setup(
                repository =>
                repository.SaveAsync(It.IsAny <IEnumerable <IEntityStateEntry> >(), It.IsAny <CancellationToken>()))
            .Returns(() => Empty.TrueTask);
            SetupEditableWrapper(true);
            InitializeRepository();

            var viewModel = GetViewModel <OrderWorkspaceViewModel>();

            viewModel.AddOrderCommand.Execute(null);
            Assert.IsTrue(viewModel.HasChanges);

            viewModel.SaveChangesCommand.Execute(null);
            Assert.IsFalse(viewModel.HasChanges);
            RepositoryMock.Verify(
                repository =>
                repository.SaveAsync(It.IsAny <IEnumerable <IEntityStateEntry> >(), It.IsAny <CancellationToken>()),
                Times.Once);
        }
        public void AllPages_Should_Load_From_Cache(bool loadPageContent)
        {
            string cacheKey = (loadPageContent) ? (CacheKeys.AllPagesWithContent()) : (CacheKeys.AllPages());

            // Arrange
            RepositoryMock repository = new RepositoryMock();
            CacheMock      listCache  = new CacheMock();

            PageService   pageService   = CreatePageService(null, listCache, repository);
            PageViewModel expectedModel = CreatePageViewModel();

            AddListCacheItem(listCache, cacheKey, new List <PageViewModel>()
            {
                expectedModel
            });

            // Act
            IEnumerable <PageViewModel> actualList = pageService.AllPages(loadPageContent);

            // Assert
            Assert.That(actualList, Contains.Item(expectedModel));
        }
Example #43
0
        public async Task GetAllOrderedByNameDescendingAsync_GoodFlow([ProjectDataSource(10)] List <Project> projects)
        {
            RepositoryMock.Setup(
                repository => repository.GetAllWithUsersAsync(null, null, project => project.Name, false, null))
            .Returns(
                Task.FromResult(projects)
                );

            List <Project> retrievedProjects = await Service.GetAllWithUsersAsync(new ProjectFilterParams()
            {
                Page          = null,
                AmountOnPage  = null,
                Highlighted   = null,
                SortBy        = "name",
                SortDirection = "desc"
            });

            Assert.DoesNotThrow(() => {
                RepositoryMock.Verify(repository => repository.GetAllWithUsersAsync(null, null, project => project.Name, false, null), Times.Once);
            });

            Assert.AreEqual(projects, retrievedProjects);
        }
Example #44
0
        public async Task GetCallToActionOptionsFromTypeAsync_GoodFlow([CallToActionOptionDataSource(30)] IEnumerable <CallToActionOption> options)
        {
            // Arrange
            RepositoryMock
            .Setup(repository => repository.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>()))
            .ReturnsAsync(options);

            // Act
            IEnumerable <CallToActionOption> actualOptions =
                await Service.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>());

            Action act = () =>
                         RepositoryMock.Verify(repository => repository.GetCallToActionOptionsFromTypeAsync(It.IsAny <string>()),
                                               Times.Once());

            // Assert
            act.Should()
            .NotThrow();
            actualOptions
            .Should().Contain(options);
            actualOptions.Count()
            .Should().Be(30);
        }
Example #45
0
        public void Should_Release_Write_Main_And_Secondardy_Locks()
        {
            bool mainReleased = false;

            RepositoryMock.Setup(rep => rep.ReleaseReadLock("xxx", It.IsAny <string>()))
            .Callback(() => mainReleased = true);

            RepositoryMock.Setup(rep => rep.ReleaseLock(It.IsAny <LockItem>()))
            .Callback(() => Assert.IsTrue(mainReleased));

            //make sure putting the guard into a using construct eventually releases the lock
            using (var grd = new ResourceLockGuard(Lock, RepositoryMock.Object)
            {
                SecondaryLocks = SecondaryLocks
            })
            {
            }


            RepositoryMock.Verify(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId), Times.Once());
            RepositoryMock.Verify(rep => rep.ReleaseLock(It.IsAny <LockItem>()), Times.Exactly(SecondaryLocks.Count));
            RepositoryMock.Verify(rep => rep.ReleaseWriteLock(Lock.ResourceId, Lock.LockId), Times.Never());
        }
Example #46
0
        public async Task GetAllNoHighlightedAsync_GoodFlow([ProjectDataSource(10)] List <Project> projects)
        {
            RepositoryMock.Setup(
                repository => repository.GetAllWithUsersAndCollaboratorsAsync(null, null, project => project.Updated, true, false))
            .Returns(
                Task.FromResult(projects)
                );

            List <Project> retrievedProjects = await Service.GetAllWithUsersAndCollaboratorsAsync(new ProjectFilterParams()
            {
                Page          = null,
                AmountOnPage  = null,
                Highlighted   = false,
                SortBy        = null,
                SortDirection = "asc"
            });

            Assert.DoesNotThrow(() => {
                RepositoryMock.Verify(repository => repository.GetAllWithUsersAndCollaboratorsAsync(null, null, project => project.Updated, true, false), Times.Once);
            });

            Assert.AreEqual(projects, retrievedProjects);
        }
Example #47
0
		public void GetById_Should_Add_To_Cache_When_PageSummary_Does_Not_Exist_In_Cache()
		{
			// Arrange
			RepositoryMock repository = new RepositoryMock();
			CacheMock pageModelCache = new CacheMock();
			PageService pageService = CreatePageService(pageModelCache, null, repository);

			PageViewModel expectedModel = CreatePageViewModel();
			expectedModel = pageService.AddPage(expectedModel); // get it back to update the version no.

			// Act
			pageService.GetById(1);

			// Assert
			CacheItem cacheItem = pageModelCache.CacheItems.First();
			string cacheKey = CacheKeys.PageViewModelKey(1, PageViewModelCache.LATEST_VERSION_NUMBER);
			Assert.That(cacheItem.Key, Is.EqualTo(cacheKey));

			PageViewModel actualModel = (PageViewModel) cacheItem.Value;
			Assert.That(actualModel.Id, Is.EqualTo(expectedModel.Id));
			Assert.That(actualModel.VersionNumber, Is.EqualTo(expectedModel.VersionNumber));
			Assert.That(actualModel.Title, Is.EqualTo(expectedModel.Title));
		}
        public void DeleteNonExistingNewsItem()
        {
            var repo = new RepositoryMock<News>();
            var controller = new NewsController(repo);
            this.SetupController(controller, "news");

            var deleteResult = controller.DeletelNews(20).ExecuteAsync(new CancellationToken()).Result;

            Assert.AreEqual(HttpStatusCode.BadRequest, deleteResult.StatusCode);
        }
Example #49
0
		public void Settings_Should_Save_To_Repository_When_Repository_Has_No_Settings()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			RepositoryMock repository = new RepositoryMock();

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(repository.TextPlugins.Count, Is.EqualTo(1));
			Assert.That(repository.TextPlugins.FirstOrDefault(), Is.EqualTo(plugin));
		}
Example #50
0
		public void Settings_Should_Call_OnInitializeSettings_When_Repository_Has_No_Settings()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			RepositoryMock repository = new RepositoryMock();

			Mock<TextPluginStub> pluginMock = new Mock<TextPluginStub>();
			pluginMock.Setup(x => x.Id).Returns("SomeId");
			pluginMock.Object.PluginCache = pluginCacheMock.Object;
			pluginMock.Object.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = pluginMock.Object.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			pluginMock.Verify(x => x.OnInitializeSettings(It.IsAny<PluginSettings>()), Times.Once);
		}
Example #51
0
		public void Settings_Should_Default_Version_To_1_If_Version_Is_Empty()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			RepositoryMock repository = new RepositoryMock();

			TextPluginStub plugin = new TextPluginStub("id", "name", "desc", "");
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings.Version, Is.EqualTo("1.0"));
		}
Example #52
0
		public void Settings_Should_Throw_Exception_If_Id_Is_Not_Set()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			RepositoryMock repository = new RepositoryMock();

			TextPluginStub plugin = new TextPluginStub("","","","");
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act + Assert
			PluginSettings actualPluginSettings = plugin.Settings;
		}
        public void PostNewsItem_WithInvalidData_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Title = "Bad Item",
                PublishDate = DateTime.Now.AddDays(8)
            };

            // Act
            var httpResponseMessage = controller.PostNewsItem(newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseMessage.StatusCode);
        }
Example #54
0
		public void Settings_Should_Load_From_Repository_When_Cache_Is_Not_Set()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();

			PluginSettings expectedPluginSettings = new PluginSettings("mockplugin", "1.0");
			expectedPluginSettings.SetValue("repository", "test");
			RepositoryMock repository = new RepositoryMock();
			repository.PluginSettings = expectedPluginSettings;

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.GetValue("repository"), Is.EqualTo("test"));
		}
        public void GetNewsItemByID_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            // Act
            var resultPostAction = controller.GetNewsItem(1).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, resultPostAction.StatusCode);
        }
 public void Setup()
 {
     _pluginFactory = new PluginFactoryMock();
     _repositoryMock = new RepositoryMock();
 }
        public void ModifyNewsItem_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Id = 2,
                Title = "fourt",
                Content = "fourt",
                PublishDate = DateTime.Now
            };

            // Act
            var resultPostAction = controller.PutNewsItem(2, newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, resultPostAction.StatusCode);

            // Update retern only HttpStatusCode.OK
            //var content = resultPostAction.Content.ReadAsStringAsync().Result;
            //var resultNews = JsonConvert.DeserializeObject<NewsItem>(content);

            //Assert.IsNotNull(resultNews.PublishDate);
            //Assert.AreEqual(newNewsItem.Title, resultNews.Title);
            //Assert.AreEqual(newNewsItem.Content, resultNews.Content);
        }
        public void ModifyNonExistingNewsItem_ShouldReturnBadRequest()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Id = 4,
                Title = "fourt",
                Content = "fourt",
                PublishDate = DateTime.Now
            };

            // Act
            var resultPostAction = controller.PutNewsItem(4, newNewsItem).ExecuteAsync(new CancellationToken()).Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, resultPostAction.StatusCode);
        }
Example #59
0
		public void Settings_Should_Create_Instance_When_Repository_Has_No_Settings()
		{
			// Arrange
			CacheMock cache = new CacheMock();
			ApplicationSettings appSettings = new ApplicationSettings();
			Mock<IPluginCache> pluginCacheMock = new Mock<IPluginCache>();
			RepositoryMock repository = new RepositoryMock();

			TextPluginStub plugin = new TextPluginStub();
			plugin.PluginCache = pluginCacheMock.Object;
			plugin.Repository = repository;

			// Act
			PluginSettings actualPluginSettings = plugin.Settings;

			// Assert
			Assert.That(actualPluginSettings, Is.Not.Null);
			Assert.That(actualPluginSettings.Values.Count(), Is.EqualTo(0));
		}
        public void PostNewsItem_WithValidData_ShouldSucceed()
        {
            var repo = new RepositoryMock();
            var news = GetNewsItemsNews();

            repo.Entities = news;
            var controller = new NewsController(repo);
            SetupController(controller, "news");

            var newNewsItem = new NewsItem()
            {
                Title = "ThirdNews",
                Content = "ThirdNewsContent",
                PublishDate = DateTime.Now.AddDays(8)
            };

            // Act
            var httpResponse = controller.PostNewsItem(newNewsItem).ExecuteAsync(new CancellationToken()).Result;
            var content = httpResponse.Content.ReadAsStringAsync().Result;
            var resultNews = JsonConvert.DeserializeObject<NewsItem>(content);

            // Assert
            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(httpResponse.Headers.Location);

            Assert.IsNotNull(resultNews.PublishDate);
            Assert.AreEqual(newNewsItem.Title, resultNews.Title);
            Assert.AreEqual(newNewsItem.Content, resultNews.Content);
        }