public void items_retrieves_entities_on_provided_scheduler()
        {
            var scheduler  = new TestScheduler();
            var repository = new RepositoryMock <int, TestEntity>(MockBehavior.Loose);

            repository
            .When(x => x.GetAll())
            .Return(ImmutableList <TestEntity> .Empty);
            var sut = new AsyncRepositoryBuilder()
                      .WithDataStoreScheduler(scheduler)
                      .WithRepository(repository)
                      .Build();

            sut
            .Items
            .Subscribe();

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

            repository
            .When(x => x.Get(42))
            .Return(new TestEntity());
            var sut = new AsyncRepositoryBuilder()
                      .WithDataStoreScheduler(scheduler)
                      .WithRepository(repository)
                      .Build();

            sut
            .DeleteAll()
            .Subscribe();

            repository
            .Verify(x => x.DeleteAll())
            .WasNotCalled();
            scheduler.AdvanceMinimal();
            repository
            .Verify(x => x.DeleteAll())
            .WasCalledExactlyOnce();
        }
Esempio n. 3
0
        public async Task ShouldNotOverrideRelatedWorkItems()
        {
            const string expectedEmail = "*****@*****.**";
            var          vm            = Builder <TeamMemberViewModel> .CreateNew()
                                         .With(m => m.Email = expectedEmail)
                                         .With(m => m.Id    = Guid.NewGuid())
                                         .Build();

            var identities = Builder <VSTS.Net.Models.Identity.Identity> .CreateListOfSize(3)
                             .All()
                             .With(i => i.IsActive = true)
                             .Build();

            var relatedWorkitems = Builder <int> .CreateListOfSize(10).Build().ToArray();

            _vstsIdentityClientMock.Setup(m => m.GetIdentitiesAsync(expectedEmail, true, "General", It.IsAny <CancellationToken>()))
            .ReturnsAsync(identities)
            .Verifiable();

            SetupGetRelatedWorkitems(relatedWorkitems);
            SetupCreateOrUpdate <TeamMember>(m => m.Id == identities.ElementAt(0).Id&& m.RelatedWorkItems == relatedWorkitems);

            await _handler.Handle(new SaveTeamMember { TeamMember = vm });

            RepositoryMock.Verify();
            _vstsIdentityClientMock.Verify();
        }
Esempio n. 4
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);
        }
        public void VmShouldSaveAndRestoreStateHasChangesFalse()
        {
            var models = new List <OrderModel> {
                new OrderModel()
            };

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

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

            var state = new DataContext();

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

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

            Assert.IsFalse(viewModel.HasChanges);
            RepositoryMock.Verify(repository => repository.GetOrdersAsync(It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(models));
        }
        public void RemoveCmdShouldAddChangesResultYes()
        {
            var items = new List <OrderModel>
            {
                new OrderModel {
                    Id = Guid.NewGuid()
                }
            };
            IList <OrderProductModel> links = new List <OrderProductModel>();

            RepositoryMock
            .Setup(repository => repository.GetProductsByOrderAsync(items[0].Id, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(links));
            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));
            InitializeRepository(items);
            var viewModel = GetViewModel <OrderWorkspaceViewModel>();

            viewModel.GridViewModel.SelectedItem = items[0];

            viewModel.RemoveOrderCommand.Execute(null);
            Assert.IsTrue(viewModel.HasChanges);
            Assert.AreEqual(viewModel.GridViewModel.OriginalItemsSource.Count, 0);
            MessagePresenterMock.Verify(
                model =>
                model.ShowAsync(It.IsAny <string>(), It.IsAny <string>(), MessageButton.YesNo, MessageImage.Question,
                                It.IsAny <MessageResult>(), It.IsAny <IDataContext>()), Times.Once);
            RepositoryMock.Verify(
                repository => repository.GetProductsByOrderAsync(items[0].Id, It.IsAny <CancellationToken>()), Times.Once);
        }
        public void VmShouldNotBeClosedHasChangesResultCancel()
        {
            RepositoryMock
            .Setup(repository => repository.SaveAsync(It.IsAny <IEnumerable <IEntityStateEntry> >(), It.IsAny <CancellationToken>()))
            .Returns(() => Empty.TrueTask);
            MessagePresenterMock
            .Setup(box => box.ShowAsync(It.IsAny <string>(), It.IsAny <string>(), MessageButton.YesNoCancel,
                                        MessageImage.Question, It.IsAny <MessageResult>(), It.IsAny <IDataContext>()))
            .Returns(Task.FromResult(MessageResult.Cancel));
            SetupEditableWrapper(true);
            InitializeProductRepository();

            var viewModel = GetViewModel <ProductWorkspaceViewModel>();

            viewModel.AddProductCommand.Execute(null);
            Assert.IsTrue(viewModel.HasChanges);
            Assert.IsFalse(viewModel.CloseAsync(null).Result);

            MessagePresenterMock
            .Verify(model => model.ShowAsync(It.IsAny <string>(), It.IsAny <string>(), MessageButton.YesNoCancel,
                                             MessageImage.Question, It.IsAny <MessageResult>(), It.IsAny <IDataContext>()), Times.Once);
            RepositoryMock
            .Verify(repository => repository.SaveAsync(It.IsAny <IEnumerable <IEntityStateEntry> >(), It.IsAny <CancellationToken>()),
                    Times.Never);
        }
        public void VmShouldSaveAndRestoreStateHasChangesFalse()
        {
            var productModels = new List <ProductModel>
            {
                new ProductModel {
                    Id = Guid.NewGuid(), Name = "Test"
                },
                new ProductModel {
                    Id = Guid.NewGuid(), Name = "Test"
                },
            };

            InitializeProductRepository(productModels);
            var viewModel = GetViewModel <ProductWorkspaceViewModel>();

            Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(productModels));
            Assert.IsFalse(viewModel.HasChanges);
            RepositoryMock.Verify(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()), Times.Once);

            var state = new DataContext();

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

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

            Assert.IsFalse(viewModel.HasChanges);
            RepositoryMock.Verify(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()), Times.Once);
            Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(productModels));
        }
Esempio n. 9
0
        public async Task ShouldReturnEmptyReportForEachMemberIfNoPullRequests()
        {
            const int expectedTeamMembersCount = 6;
            var       members = Builder <TeamMemberViewModel> .CreateListOfSize(expectedTeamMembersCount)
                                .Build();

            var profile = Builder <ProfileViewModel> .CreateNew()
                          .With(p => p.Members      = members.Select(m => m.Id).ToArray())
                          .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().HaveCount(expectedTeamMembersCount);
                report.IndividualReports.Should().OnlyContain(r => r.IsEmpty);
            });

            DataSourceMock.VerifyAll();
            RepositoryMock.Verify();
        }
Esempio n. 10
0
        public async Task ShouldKeepUpdatingWorkitemsIfOneUpdateFails()
        {
            var workitems = Builder <WorkItemViewModel> .CreateListOfSize(8)
                            .All()
                            .With((w, idx) => w.WorkItemId = idx)
                            .Build();

            var member = Builder <TeamMemberViewModel> .CreateNew().Build();

            var memberDto = Builder <TeamMember> .CreateNew()
                            .With(m => m.RelatedWorkItems, Enumerable.Range(20, 3).ToArray())
                            .Build();

            var combinedIds = workitems.Select(w => w.WorkItemId).Union(memberDto.RelatedWorkItems).ToArray();

            SetupSingle(memberDto);
            SetupCreateOrUpdateIfManual <WorkItem>(_ => true, i => i.WorkItemId == 2)
            .Throws <Exception>();
            SetupCreateOrUpdateIfManual <WorkItem>(_ => true, i => i.WorkItemId != 2)
            .ReturnsAsync(true);
            RepositoryMock.Setup(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, int[]> > >(), It.Is <int[]>(v => CheckIfRelatedWorkitemsAreCorrect(v, combinedIds))))
            .Returns(Task.CompletedTask)
            .Verifiable();
            RepositoryMock.Setup(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, DateTime?> > >(), It.IsAny <DateTime>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            await _handler.Handle(new SaveWorkItemsForUser(workitems, member));

            RepositoryMock.Verify(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, int[]> > >(), It.IsAny <int[]>()), Times.Once());
            RepositoryMock.Verify(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, DateTime?> > >(), It.IsAny <DateTime>()), Times.Once());
            RepositoryMock.Verify(r => r.CreateOrUpdateIfAsync(It.IsAny <Expression <Func <WorkItem, bool> > >(), It.IsAny <WorkItem>()), Times.Exactly(workitems.Count));
        }
Esempio n. 11
0
        public async Task ShouldReturnCorrectReportType()
        {
            const int expectedNumberOfReports = 5;
            var       id = Guid.NewGuid();
            var       individualReports = Builder <AggregatedWorkitemsETAReport.IndividualETAReport>
                                          .CreateListOfSize(expectedNumberOfReports).Build();

            var report = new AggregatedWorkitemsETAReport(expectedNumberOfReports);

            report.IndividualReports.AddRange(individualReports);

            RepositoryMock.Setup(r => r.GetFieldValueAsync(It.IsAny <Expression <Func <ReportResult, bool> > >(), It.IsAny <Expression <Func <ReportResult, string> > >()))
            .ReturnsAsync(Constants.ETAReportType.ToLower())
            .Verifiable();
            RepositoryMock.Setup(r => r.GetSingleAsync(id, It.Is <Type>(t => t == typeof(AggregatedWorkitemsETAReport))))
            .ReturnsAsync(report)
            .Verifiable();

            var result = await _handler.Handle(new GetReportById(id));

            result.Should().NotBeNull();
            result.Should().BeOfType <AggregatedWorkitemsETAReportViewModel>();
            result.As <AggregatedWorkitemsETAReportViewModel>().IndividualReports.Should().HaveCount(expectedNumberOfReports);
            RepositoryMock.Verify();
        }
Esempio n. 12
0
        public async Task ShouldFetchIdentityIdFromVsts()
        {
            const string expectedEmail = "*****@*****.**";
            var          vm            = Builder <TeamMemberViewModel> .CreateNew()
                                         .With(m => m.Email = expectedEmail)
                                         .With(m => m.Id    = Guid.Empty)
                                         .Build();

            var identities = Builder <VSTS.Net.Models.Identity.Identity> .CreateListOfSize(3)
                             .All()
                             .With(i => i.IsActive = true)
                             .Build();

            _vstsIdentityClientMock.Setup(m => m.GetIdentitiesAsync(expectedEmail, true, "General", default(CancellationToken)))
            .ReturnsAsync(identities)
            .Verifiable();

            SetupGetRelatedWorkitems(new int[0]);
            SetupCreateOrUpdate <TeamMember>(m => m.Id == identities.ElementAt(0).Id);

            await _handler.Handle(new SaveTeamMember { TeamMember = vm });

            RepositoryMock.Verify();
            _vstsIdentityClientMock.Verify();
        }
        public void EditCmdShouldAddChangesResultTrue()
        {
            var items = new List <OrderModel>
            {
                new OrderModel {
                    Id = Guid.NewGuid()
                }
            };
            IList <OrderProductModel> links = new List <OrderProductModel>();

            RepositoryMock
            .Setup(repository => repository.GetProductsByOrderAsync(items[0].Id, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(links));
            var wrapper = SetupEditableWrapper(true);

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

            viewModel.GridViewModel.SelectedItem = items[0];

            viewModel.EditOrderCommand.Execute(null);
            Assert.IsTrue(viewModel.HasChanges);
            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);
        }
        public async Task DeleteAsync_ValidCall()
        {
            await HomeworkService.DeleteAsync(It.IsAny <int>());

            RepositoryMock.Verify(m => m.Delete(It.IsAny <Homework>()));
            StudentHomeworkUpdaterMock.Verify(s => s.UpdateAsync(It.IsAny <Homework>(),
                                                                 StudentHomeworkUpdater.UpdateType.RemoveHomework, It.IsAny <bool>()));
        }
        public async Task CreateAsync_ValidCall()
        {
            await HomeworkService.CreateAsync(_homeworkDTO);

            RepositoryMock.Verify(m => m.CreateAsync(It.IsAny <Homework>()));
            StudentHomeworkUpdaterMock.Verify(s => s.UpdateAsync(It.IsAny <Homework>(),
                                                                 StudentHomeworkUpdater.UpdateType.AddHomework, It.IsAny <bool>()));
        }
        public async Task UpdateAsync_ValidCall_WhenUpdateStudentWithOneId()
        {
            await HomeworkService.UpdateAsync(_homeworkDTO);

            RepositoryMock.Verify(m => m.Update(It.IsAny <Homework>()));
            StudentHomeworkUpdaterMock.Verify(s => s.UpdateAsync(It.IsAny <Homework>(),
                                                                 StudentHomeworkUpdater.UpdateType.UpdateHomework, It.IsAny <bool>()));
        }
Esempio n. 17
0
        public async Task ShouldCorrectlyPoulateAllPullRequestInfo()
        {
            var expecetedPullRequest = new PullRequest
            {
                Id            = Guid.NewGuid(),
                Created       = DateTime.UtcNow.AddDays(-20),
                Completed     = DateTime.UtcNow.AddDays(-5),
                Author        = "Author 1",
                AuthorId      = Guid.NewGuid(),
                State         = PullRequestState.Completed,
                Iterations    = 4,
                Comments      = 8,
                PullRequestId = 1246587,
                Title         = "Test PR",
                Repository    = Guid.NewGuid(),
                LastSync      = DateTime.UtcNow
            };

            var activePullRequest = Builder <PullRequest>
                                    .CreateNew()
                                    .With(p => p.Id, expecetedPullRequest.Id)
                                    .With(p => p.PullRequestId, expecetedPullRequest.PullRequestId)
                                    .With(p => p.LastSync, expecetedPullRequest.LastSync)
                                    .With(p => p.Repository, expecetedPullRequest.Repository)
                                    .With(p => p.State, PullRequestState.Active)
                                    .Build();

            SetupMultiple(VerifyPredicateForActivePullRequests, new[] { activePullRequest });
            SetupCreateOrUpdate <PullRequest>();
            SetupRepository();
            SetupProject();
            SetupOrganization();
            SetupIterations(expecetedPullRequest.Iterations);
            SetupThreads(expecetedPullRequest.Comments);

            PullRequestsClient.Setup(c => c.GetPullRequestAsync(expecetedPullRequest.PullRequestId, default))
            .ReturnsAsync(new VSTS.Net.Models.PullRequests.PullRequest
            {
                PullRequestId = expecetedPullRequest.PullRequestId,
                ClosedDate    = expecetedPullRequest.Completed,
                CreationDate  = expecetedPullRequest.Created,
                CreatedBy     = new VSTS.Net.Models.Identity.IdentityReference {
                    Id = expecetedPullRequest.AuthorId, UniqueName = expecetedPullRequest.Author
                },
                Title      = expecetedPullRequest.Title,
                Status     = "Completed",
                Repository = new VSTS.Net.Models.Common.Repository {
                    Id = Guid.NewGuid(), Project = new VSTS.Net.Models.Common.Project {
                    }
                },
            });

            await _handler.Handle(new Vsts.Commands.UpdateActivePullRequests());

            RepositoryMock.Verify(r => r.CreateOrUpdateAsync(It.Is <PullRequest>(p => VerifyPullRequest(p, expecetedPullRequest))), Times.Once());
        }
Esempio n. 18
0
        public async Task ShouldNotDoAnythingIfNoWorkitems()
        {
            var member = Builder <TeamMemberViewModel> .CreateNew().Build();

            await _handler.Handle(new SaveWorkItemsForUser(Enumerable.Empty <WorkItemViewModel>(), member));

            RepositoryMock.Verify(r => r.CreateOrUpdateAsync(It.IsAny <WorkItem>()), Times.Never);
            RepositoryMock.Verify(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, object> > >(), It.IsAny <int[]>()), Times.Never);
            RepositoryMock.Verify(r => r.UpdateFieldValue(It.IsAny <TeamMember>(), It.IsAny <Expression <Func <TeamMember, object> > >(), It.IsAny <DateTime>()), Times.Never);
        }
Esempio n. 19
0
        public async Task ShouldReturnNullIfUnsupportedReportType()
        {
            RepositoryMock.Setup(r => r.GetFieldValueAsync(It.IsAny <Expression <Func <ReportResult, bool> > >(), It.IsAny <Expression <Func <ReportResult, string> > >()))
            .ReturnsAsync("FakeReportType")
            .Verifiable();

            var result = await _handler.Handle(new GetReportById(Guid.NewGuid()));

            result.Should().BeNull();
            RepositoryMock.Verify();
        }
Esempio n. 20
0
        public void OneQueryTest()
        {
            var dto = new Dto {
                One = 12
            };
            var s = query1;

            query1.Query(dto);
            query1.Query(dto);
            RepositoryMock.Verify(x => x.GetSomething(), Times.Once);
        }
Esempio n. 21
0
        public void ChassiFind_Not_Find_Repositori_Without_Chassi(string chassi)
        {
            // Arrange

            // Act
            var result = Service.ChassiFind(chassi);

            // Assert
            Assert.IsNull(result, "Veículo não encontrado.");
            RepositoryMock.Verify(r => r.ChassiFind(It.IsAny <string>()), Times.Never(), "Não realizou a pesquisa no repositório.");
        }
Esempio n. 22
0
        public async Task ShouldCorrectlyCalculateMetricsForEachMember()
        {
            const int expectedTeamMembersCount = 2;
            var       start   = DateTime.Now.AddDays(-7);
            var       end     = DateTime.Now;
            var       members = Builder <TeamMemberViewModel> .CreateListOfSize(4)
                                .Build();

            var memberIds           = members.Take(2).Select(m => m.Id).ToArray();
            var additionalMemberIds = members.TakeLast(2).Select(m => m.Id).ToArray();
            var repositories        = new[] { Guid.NewGuid(), Guid.NewGuid() };
            var profile             = Builder <ProfileViewModel> .CreateNew()
                                      .With(p => p.Members      = memberIds)
                                      .With(p => p.Repositories = repositories)
                                      .Build();

            var pullRequests = GetPullRequests(start, end, memberIds, repositories)
                               .Union(GetPullRequests(start, end, memberIds, new[] { Guid.NewGuid(), Guid.NewGuid() }))
                               .Union(GetPullRequests(start, end, additionalMemberIds, repositories))
                               .ToArray();

            SetupGetProfile(profile);
            SetupGetTeamMember(members);
            SetupGetPullRequests(pullRequests);

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

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

                firstMemberReport.Created.Should().Be(7);
                firstMemberReport.Active.Should().Be(4);
                firstMemberReport.Completed.Should().Be(3);
                firstMemberReport.Abandoned.Should().Be(2);
                firstMemberReport.TotalIterations.Should().Be(9);
                firstMemberReport.TotalComments.Should().Be(18);

                secondMemberReport.Created.Should().Be(7);
                secondMemberReport.Active.Should().Be(5);
                secondMemberReport.Completed.Should().Be(6);
                secondMemberReport.Abandoned.Should().Be(1);
                secondMemberReport.TotalIterations.Should().Be(12);
                secondMemberReport.TotalComments.Should().Be(24);
            });

            DataSourceMock.VerifyAll();
            RepositoryMock.Verify();
        }
        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();
        }
Esempio n. 24
0
        public async Task GetAllAsync([RoleDataSource(10)] List <Role> roles)
        {
            RepositoryMock.Setup(repository => repository.GetAllAsync())
            .Returns(Task.FromResult(roles));

            List <Role> retrievedRoles = await Service.GetAllAsync();

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

            Assert.AreEqual(roles, retrievedRoles);
            Assert.AreEqual(10, retrievedRoles.Count);
        }
        public void VmShouldLoadProductsFromRepository()
        {
            var productModels = new List <ProductModel> {
                new ProductModel()
            };

            InitializeProductRepository(productModels);
            var viewModel = GetViewModel <ProductWorkspaceViewModel>();

            Assert.IsTrue(viewModel.GridViewModel.OriginalItemsSource.SequenceEqual(productModels));
            RepositoryMock.Verify(repository => repository.GetProductsAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
        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 VmShouldLoadOrdersFromRepository()
        {
            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);
        }
Esempio n. 28
0
        public void ChassiFind_Not_Found_By_The_Repository(string chassi)
        {
            // Arrange
            RepositoryMock.Setup(r => r.ChassiFind(It.IsAny <string>())).Returns <Vehicle>(null);

            // Act
            var result = Service.ChassiFind(chassi);

            // Assert
            Assert.IsNull(result, "Veículo não encontrado.");
            RepositoryMock.Verify(r => r.ChassiFind(It.IsAny <string>()), Times.Once(), "Realizou a pesquisa no repositório.");
            RepositoryMock.Verify(r => r.ChassiFind(chassi), Times.Once(), "Pesquisou apenas o chassi solicitado.");
        }
        public void Should_Release_Lock_On_Dispose()
        {
            //mock.Setup(rep => rep.ReleaseReadLock(LockItem.ResourceId, LockItem.LockId)).Returns(true);

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

            RepositoryMock.Verify(rep => rep.ReleaseWriteLock(Lock.ResourceId, Lock.LockId));
            RepositoryMock.Verify(rep => rep.ReleaseReadLock(Lock.ResourceId, Lock.LockId), Times.Never());
            RepositoryMock.Verify(rep => rep.ReleaseLock(Lock), Times.Never());
        }
Esempio n. 30
0
        public async Task RemoveUserAsync_GoodFlow()
        {
            int userId = 1;

            RepositoryMock.Setup(
                repository => repository.RemoveUserAsync(userId));

            await Service.RemoveUserAsync(userId);

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