Пример #1
0
        public void DecorateLineTests_IndexTesting_ExpectedBehavior(string text, int start, int end, int[] spans, int colorIndex)
        {
            decorator.DecorateLine(text, start, end);

            if (spans.Length > 1)
            {
                int correctLength = spans[1] - spans[0];

                mocker.Verify <IBackgroundTextIndexDrawer>(
                    p => p.DrawBackground(
                        spans[0], It.IsIn(correctLength),
                        rainbowgetter.GetColorByIndex(colorIndex)),
                    Times.Once()
                    );
            }

            mocker.Verify <IBackgroundTextIndexDrawer>(
                p => p.DrawBackground(
                    It.IsNotIn(spans),
                    It.IsNotIn(4),
                    It.IsAny <Brush>()
                    ),
                Times.Never()
                );
        }
Пример #2
0
        public void TestExecuteWithoutCanalNullSholdNotInvokeAllMethods()
        {
            //Arrange
            _model.canal = null;
            _model.nome  = _str;
            _model.valor = _str;
            _model.obs   = _str;

            _mocker.GetMock <IContatoRepository>();

            _mocker.GetMock <IContatoFactory>();

            _mocker.GetMock <ICreateContatoRule>()
            .Setup(x => x.IsValid(It.IsAny <CreateContatoModel>(), It.IsAny <ICommand>()))
            .Returns(true);

            _command = _command = new CreateContatoCommand(
                _mocker.Resolve <IContatoRepository>(),
                _mocker.Resolve <IContatoFactory>(),
                new List <ICreateContatoRule> {
                _mocker.Resolve <ICreateContatoRule>()
            }
                );

            //Act
            _command.Execute(_model).Wait();

            //Assert
            _mocker.Verify <IContatoFactory>(x => x.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never(), "Não foi possivel completar a execução");
            _mocker.Verify <IContatoRepository>(x => x.Add(It.IsAny <Contato>()), Times.Never(), "Não foi possivel completar a execução");
        }
Пример #3
0
        public async Task Should_Try_Analyse_Projects_With_Runsettings(bool useMsCodeCoverageOption)
        {
            var runMsCodeCoverage = useMsCodeCoverageOption ? RunMsCodeCoverage.Yes : RunMsCodeCoverage.IfInRunSettings;

            SetupAppOptionsProvider(runMsCodeCoverage);

            var fccMsTestAdapterPath = InitializeFCCMsTestAdapterPath();

            var coverageProjectWithRunSettings = CreateCoverageProject(".runsettings");
            var templatedCoverageProject       = CreateCoverageProject(null);
            var coverageProjects = new List <ICoverageProject> {
                coverageProjectWithRunSettings, templatedCoverageProject
            };
            var testOperation = SetUpTestOperation(coverageProjects);

            await msCodeCoverageRunSettingsService.IsCollectingAsync(testOperation);

            autoMocker.Verify <IUserRunSettingsService>(
                userRunSettingsService => userRunSettingsService.Analyse(
                    new List <ICoverageProject> {
                coverageProjectWithRunSettings
            },
                    useMsCodeCoverageOption,
                    fccMsTestAdapterPath)
                );
        }
        public void CanDetermineContainsFilter()
        {
            // arrange
            var mocker = new AutoMoqer();

            mocker.GetMock <IQueryBuilderFactory>()
            .Setup(m => m.Create <JObject>())
            .Returns(() => mocker.GetMock <IQueryBuilder <JObject> >().Object);
            const string columnName     = "someColumnName";
            const string filterValue    = "someFilterValue";
            var          expectedFilter = new ContainsFilter(columnName, filterValue);
            var          addedFilters   = new List <IFilter <JObject> >();

            mocker.GetMock <IQueryBuilder <JObject> >()
            .Setup(m => m.AddFilter(It.IsAny <IFilter <JObject> >()))
            .Callback <IFilter <JObject> >(filter => addedFilters.Add(filter));
            mocker.GetMock <IQueryBuilder <JObject> >()
            .Setup(m => m.Build())
            .Returns(() => new Query <JObject>(addedFilters));
            var input = new List <KeyValuePair <string, StringValues> >
            {
                new KeyValuePair <string, StringValues>(columnName, new StringValues(filterValue))
            };
            var target = mocker.Create <HttpQueryJsonConverter>();

            // act
            var result = target.Convert(input) as Query <JObject>;

            // assert
            mocker.Verify <IQueryBuilder <JObject> >(m => m.AddFilter(expectedFilter), Times.Once());
            mocker.Verify <IQueryBuilder <JObject> >(m => m.Build(), Times.Once());
            Assert.NotEmpty(result.Filters);
            Assert.Equal(addedFilters, result.Filters);
        }
Пример #5
0
        public async Task Should_Log_VSTest_Run_With_Settings()
        {
            mockCoverageProject.Setup(cp => cp.ProjectName).Returns("TestProject");
            mockDataCollectorSettingsBuilder.Setup(sb => sb.Build()).Returns("settings string");
            await coverletDataCollectorUtil.RunAsync(false);

            mocker.Verify <ILogger>(l => l.Log(coverletDataCollectorUtil.LogRunMessage("settings string")));
        }
Пример #6
0
        public void Should_Try_Empty_Provided_Output_Folder()
        {
            SetUpProviders(true, "Provided", "_");
            var coverageToolOutputManager = mocker.Create <CoverageToolOutputManager>();

            coverageToolOutputManager.SetProjectCoverageOutputFolder(coverageProjects);
            mocker.Verify <IFileUtil>(f => f.TryEmptyDirectory("Provided"));
        }
        public void Should_Initialize_The_GlobalTool_And_DataCollector()
        {
            var ct = CancellationToken.None;

            coverletUtil.Initialize("folder path", ct);
            mocker.Verify <ICoverletConsoleUtil>(g => g.Initialize("folder path", ct));
            mocker.Verify <ICoverletDataCollectorUtil>(dc => dc.Initialize("folder path", ct));
        }
        public async Task Should_Combined_Log_When_No_Cobertura_Files()
        {
            await RunAndProcessReportAsync(null, Array.Empty <string>());

            autoMocker.Verify <ILogger>(logger => logger.Log("No cobertura files for ms code coverage."));
            autoMocker.Verify <IReportGeneratorUtil>(
                reportGenerator => reportGenerator.LogCoverageProcess("No cobertura files for ms code coverage.")
                );
        }
Пример #9
0
        public void Initialize_Should_Initialize_The_Coverage_Utils()
        {
            var coverageUtilManager = mocker.Create <CoverageUtilManager>();
            var ct = CancellationToken.None;

            coverageUtilManager.Initialize("AppDataFolder", ct);
            mocker.Verify <ICoverletUtil>(coverletUtil => coverletUtil.Initialize("AppDataFolder", ct));
            mocker.Verify <IOpenCoverUtil>(coverletUtil => coverletUtil.Initialize("AppDataFolder", ct));
        }
Пример #10
0
        public void Can_verify_all()
        {
            var mocked = mocker.Create <ClassWithMultipleDependencies>();

            mocker.GetMock <IDependency>().Setup(m => m.Something()).Verifiable();
            mocker.GetMock <IOtherDependency>().Setup(m => m.SomethingElse()).Verifiable();
            mocked.ConditionallyUseDepedencies(true, true);
            mocker.Verify();
        }
        public async Task WhenRetrivingCostEstimationItShouldCallRequiredService()
        {
            //Act
            var estimationViewModel = await _estimationOrchestrator.CostEstimation(HashedAccountId, EstimationName, false);

            // Assert
            _autoMoq.Verify <IHashingService>(o => o.DecodeValue(HashedAccountId));
            _autoMoq.Verify <IAccountEstimationRepository>(o => o.Get(It.IsAny <long>()));
            _autoMoq.Verify <IAccountEstimationProjectionRepository>(o => o.Get(It.IsAny <AccountEstimation>()));
        }
Пример #12
0
        public void Should_Log_Response_Output_With_Error_Title_If_Non_Success_ExitCode_And_Throw_Error_False()
        {
            var executeResponse = new ExecuteResponse();

            executeResponse.ExitCode = 999;
            executeResponse.Output   = "This will be logged";
            Assert.False(processor.Process(executeResponse, exitCode =>
            {
                return(false);
            }, false, "title", successCallback));

            Assert.IsFalse(successCallbackCalled);
            mocker.Verify <ILogger>(l => l.Log("title Error", "This will be logged"));
        }
Пример #13
0
        public void Should_Create_Zip_Destination_From_Version_And_Extract_If_Destination_Does_Not_Exist()
        {
            var zipDestination = toolFolder.EnsureUnzipped(appDataFolder.FullName, "ToolFolder", new ZipDetails {
                Version = "3.0", Path = "zipPath"
            });

            mocker.Verify <IZipFile>(z => z.ExtractToDirectory("zipPath", zipDestination));
            Assert.IsTrue(Directory.Exists(zipDestination));
            var zipDestinationDirectory = new DirectoryInfo(zipDestination);

            Assert.AreEqual("ToolFolder", zipDestinationDirectory.Parent.Name);
            Assert.AreEqual(appDataFolder.FullName, zipDestinationDirectory.Parent.Parent.FullName);
            var zipDestinationName = new DirectoryInfo(zipDestination).Name;

            Assert.AreEqual(zipDestinationName, "3.0");
        }
Пример #14
0
        public void Should_Log_Exception_Thrown_In_LoadSettingsFromStorage()
        {
            var    exception     = new Exception("msg");
            string _propertyName = null;

            mockWritableSettingsStore.Setup(
                writableSettingsStore => writableSettingsStore.PropertyExists("FineCodeCoverage", It.IsAny <string>())
                ).Returns(true);
            mockWritableSettingsStore.Setup(
                writableSettingsStore => writableSettingsStore.GetString("FineCodeCoverage", It.IsAny <string>())
                ).Callback <string, string>((_, propertyName) => _propertyName = propertyName).Throws(exception);

            appOptionsProvider.LoadSettingsFromStorage(new Mock <IAppOptions>().Object);

            autoMocker.Verify <ILogger>(logger => logger.Log($"Failed to load '{_propertyName}' setting", exception));
        }
        public void Should_Log_Output_And_Return_Null_When_Parsing_Error()
        {
            var parsing      = "this will be parsed";
            var mockExecutor = mocker.GetMock <IDotNetToolListExecutor>();

            mockExecutor.Setup(executor => executor.Global()).Returns(new DotNetToolListExecutionResult {
                ExitCode = 0, Output = parsing
            });
            var mockParser = mocker.GetMock <IDotNetToolListParser>();

            mockParser.Setup(parser => parser.Parse(parsing)).Throws(new System.Exception());
            var coverletToolDetails = dotNetToolListCoverlet.Global();

            Assert.IsNull(coverletToolDetails);
            mocker.Verify <ILogger>(l => l.Log("Dotnet tool list Coverlet Error parsing", parsing));
        }
Пример #16
0
        public void Should_Initilize_IFCCCoverletConsoleExeProvider()
        {
            var ct = CancellationToken.None;

            coverletConsoleUtil.Initialize("appDataFolder", ct);
            mocker.Verify <IFCCCoverletConsoleExecutor>(fccExeProvider => fccExeProvider.Initialize("appDataFolder", ct));
        }
Пример #17
0
        public void Can_verify_a_resolved_interface()
        {
            var mockedInterface = mocker.Create <IDependency>();

            mockedInterface.Something();

            mocker.Verify <IDependency>(a => a.Something(), Times.Once());
        }
Пример #18
0
        public async Task Clean_Up_Should_Remove_Generated_Project_RunSettings()
        {
            var coverageProjects = new List <ICoverageProject> {
                new Mock <ICoverageProject>().Object
            };
            await templatedRunSettingsService.CleanUpAsync(coverageProjects);

            autoMocker.Verify <IProjectRunSettingsGenerator>(
                projectRunSettingsGenerator => projectRunSettingsGenerator.RemoveGeneratedProjectSettingsAsync(coverageProjects)
                );
        }
Пример #19
0
        public void Should_Log_When_Enabled_And_Unsuccessful()
        {
            var mockCoverageProject = new Mock <ICoverageProject>();

            mockCoverageProject.Setup(cp => cp.Settings.CoverletConsoleGlobal).Returns(true);
            var dotNetToolListCoverlet = mocker.GetMock <IDotNetToolListCoverlet>();

            dotNetToolListCoverlet.Setup(dotnet => dotnet.Global()).Returns((CoverletToolDetails)null);

            globalExeProvider.GetRequest(mockCoverageProject.Object, null);
            mocker.Verify <ILogger>(l => l.Log("Unable to use Coverlet console global tool"));
        }
Пример #20
0
        public void Should_Log_Output_When_Executor_Error()
        {
            var mockExecutor      = mocker.GetMock <IDotNetToolListExecutor>();
            var globalErrorOutput = "this is an error";

            mockExecutor.Setup(executor => executor.Global()).Returns(new DotNetToolListExecutionResult {
                ExitCode = 1, Output = globalErrorOutput
            });
            var coverletToolDetails = dotNetToolListCoverlet.Global();

            Assert.IsNull(coverletToolDetails);
            mocker.Verify <ILogger>(l => l.Log("Dotnet tool list Coverlet Error", globalErrorOutput));
        }
        public void DecorateLineTests_IndexTesting_ExpectedBehavior(string text, int start, int end, int[] spans)
        {
            decorator.DecorateLine(text, start, end);

            for (int i = 0; i < spans.Length - 1; i++)
            {
                mocker.Verify <IBackgroundTextIndexDrawer>(
                    p => p.DrawBackground(
                        spans[i], It.IsIn(new int[] { FSI.Length, TABI.Length }),
                        It.IsAny <Brush>()),
                    Times.Once()
                    );
            }
            mocker.Verify <IBackgroundTextIndexDrawer>(
                p => p.DrawBackground(
                    It.IsNotIn(spans),
                    It.IsNotIn(4),
                    It.IsAny <Brush>()
                    ),
                Times.Never()
                );
        }
Пример #22
0
        public void Shoul_Log_If_None_Of_The_DotNetConfig_Containing_Directories_Are_Local_Tool()
        {
            var projectOutputFolder = "projectoutputfolder";
            var mockCoverageProject = new Mock <ICoverageProject>();

            mockCoverageProject.Setup(cp => cp.Settings.CoverletConsoleLocal).Returns(true);
            mockCoverageProject.Setup(cp => cp.ProjectOutputFolder).Returns(projectOutputFolder);

            var mockDotNetConfigFinder = mocker.GetMock <IDotNetConfigFinder>();

            mockDotNetConfigFinder.Setup(f => f.GetConfigDirectories(projectOutputFolder)).Returns(new List <string> {
                "ConfigDirectory1", "ConfigDirectory2"
            });

            var mockDotNetToolListCoverlet = mocker.GetMock <IDotNetToolListCoverlet>();

            mockDotNetToolListCoverlet.Setup(dotnet => dotnet.Local("ConfigDirectory1")).Returns((CoverletToolDetails)null);
            mockDotNetToolListCoverlet.Setup(dotnet => dotnet.Local("ConfigDirectory2")).Returns((CoverletToolDetails)null);
            localExecutor.GetRequest(mockCoverageProject.Object, null);
            mocker.Verify <ILogger>(l => l.Log("Unable to use Coverlet console local tool"));
        }
        public async Task Should_Clean_Up_RunSettings_Coverage_Projects()
        {
            var autoMocker = new AutoMoqer();
            var msCodeCoverageRunSettingsService = autoMocker.Create <MsCodeCoverageRunSettingsService>();


            var mockUserRunSettingsService = autoMocker.GetMock <IUserRunSettingsService>();

            mockUserRunSettingsService.Setup(
                userRunSettingsService =>
                userRunSettingsService.Analyse(It.IsAny <IEnumerable <ICoverageProject> >(), It.IsAny <bool>(), It.IsAny <string>())
                ).Returns(new UserRunSettingsAnalysisResult());

            var mockAppOptionsProvider = autoMocker.GetMock <IAppOptionsProvider>();

            mockAppOptionsProvider.Setup(appOptionsProvider => appOptionsProvider.Get()).Returns(new Mock <IAppOptions>().Object);

            // is collecting
            var mockTestOperation          = new Mock <ITestOperation>();
            var runSettingsCoverageProject = CreateCoverageProject(".runsettings");
            var coverageProjects           = new List <ICoverageProject>
            {
                runSettingsCoverageProject,
                CreateCoverageProject(null)
            };

            mockTestOperation.Setup(testOperation => testOperation.GetCoverageProjectsAsync()).ReturnsAsync(coverageProjects);

            await msCodeCoverageRunSettingsService.IsCollectingAsync(mockTestOperation.Object);

            await msCodeCoverageRunSettingsService.TestExecutionNotFinishedAsync(mockTestOperation.Object);

            autoMocker.Verify <ITemplatedRunSettingsService>(
                templatedRunSettingsService => templatedRunSettingsService.CleanUpAsync(new List <ICoverageProject> {
                runSettingsCoverageProject
            })
                );
        }
Пример #24
0
        public async Task Should_Poll_For_Initialized()
        {
            var times          = 5;
            var initializeWait = 1000;

            fccEngine.InitializeWait = initializeWait;

            var mockInitializeStatusProvider = new Mock <IInitializeStatusProvider>();

            mockInitializeStatusProvider.SetupProperty(i => i.InitializeStatus);
            var initializeStatusProvider = mockInitializeStatusProvider.Object;

            fccEngine.Initialize(initializeStatusProvider, CancellationToken.None);

            fccEngine.ReloadCoverage(() => Task.FromResult(new List <ICoverageProject>()));
            await Task.Delay(times *initializeWait).ContinueWith(_ =>
            {
                initializeStatusProvider.InitializeStatus = InitializeStatus.Initialized;
            });

            await fccEngine.reloadCoverageTask;

            mocker.Verify <ILogger>(l => l.Log(fccEngine.GetLogReloadCoverageStatusMessage(ReloadCoverageStatus.Initializing)), Times.AtLeast(times));
        }
 public void Should_Initialize_The_GlobalTool_And_DataCollector()
 {
     coverletUtil.Initialize("folder path");
     mocker.Verify <ICoverletConsoleUtil>(g => g.Initialize("folder path"));
     mocker.Verify <ICoverletDataCollectorUtil>(dc => dc.Initialize("folder path"));
 }
Пример #26
0
 public void Should_Send_NewCoverageLinesMessage_With_Null_CoverageLines_When_ClearUI()
 {
     fccEngine.ClearUI();
     mocker.Verify <IEventAggregator>(ea => ea.SendMessage(It.Is <NewCoverageLinesMessage>(msg => msg.CoverageLines == null), null));
 }
Пример #27
0
        public async Task Should_Log_Initializing_When_Initialize()
        {
            await initializer.InitializeAsync(CancellationToken.None);

            mocker.Verify <ILogger>(l => l.Log("Initializing"));
        }
Пример #28
0
 private void VerifyLogsReloadCoverageStatus(ReloadCoverageStatus reloadCoverageStatus)
 {
     mocker.Verify <ILogger>(l => l.Log(fccEngine.GetLogReloadCoverageStatusMessage(reloadCoverageStatus)));
 }
Пример #29
0
 public void Should_Initilize_IFCCCoverletConsoleExeProvider()
 {
     coverletConsoleUtil.Initialize("appDataFolder");
     mocker.Verify <IFCCCoverletConsoleExecutor>(fccExeProvider => fccExeProvider.Initialize("appDataFolder"));
 }
 private void AssertShouldNotReloadCoverage()
 {
     mocker.Verify <IFCCEngine>(engine => engine.ReloadCoverage(It.IsAny <Func <Task <List <ICoverageProject> > > >()), Times.Never());
 }