public void then_one_exception_is_tested_for_transient()
 {
     this.detectionStrategyMock.Verify(ds => ds.IsTransient(It.IsAny <Exception>()), Times.AtLeast(1));
 }
        public void DoUtilInitialized()
        {
            "在调用初始化之后,才开始执行任务".Test(async() =>
            {
                var mock = new Mock <IWorker>();
                mock.Setup(worker => worker.DoTask(It.IsAny <List <int> >()));

                var doubleBufferTaskDoUtilInitialized = new DoubleBufferLazyInitializeTask <int>(mock.Object.DoTask);
                for (int i = 0; i < 100; i++)
                {
                    doubleBufferTaskDoUtilInitialized.AddTask(i);
                }

                var taskList = new List <Task>();

                for (int i = 0; i < 100; i++)
                {
                    taskList.Add(Task.Run(() => doubleBufferTaskDoUtilInitialized.AddTask(0)));
                }

                await Task.WhenAll(taskList);
                doubleBufferTaskDoUtilInitialized.Finish();

                var waitAllTaskFinish = doubleBufferTaskDoUtilInitialized.WaitAllTaskFinish();

                mock.Verify(worker => worker.DoTask(It.IsAny <List <int> >()), Times.Never);
                Assert.AreEqual(false, waitAllTaskFinish.IsCompleted);

                // 调用初始化完成
                doubleBufferTaskDoUtilInitialized.OnInitialized();
                await waitAllTaskFinish;
                mock.Verify(worker => worker.DoTask(It.IsAny <List <int> >()), Times.AtLeast(1));
            });

            "在调用初始化之前,不会执行任何的任务".Test(async() =>
            {
                var mock = new Mock <IWorker>();
                mock.Setup(worker => worker.DoTask(It.IsAny <List <int> >()));

                var doubleBufferTaskDoUtilInitialized = new DoubleBufferLazyInitializeTask <int>(mock.Object.DoTask);
                for (int i = 0; i < 100; i++)
                {
                    doubleBufferTaskDoUtilInitialized.AddTask(i);
                }

                var taskList = new List <Task>();

                for (int i = 0; i < 100; i++)
                {
                    taskList.Add(Task.Run(() => doubleBufferTaskDoUtilInitialized.AddTask(0)));
                }

                await Task.WhenAll(taskList);
                doubleBufferTaskDoUtilInitialized.Finish();

                var waitAllTaskFinish = doubleBufferTaskDoUtilInitialized.WaitAllTaskFinish();

                mock.Verify(worker => worker.DoTask(It.IsAny <List <int> >()), Times.Never);
                Assert.AreEqual(false, waitAllTaskFinish.IsCompleted);
            });
        }
        public void ImportApplication_ProcessStateRunning_ContinuesToCheck()
        {
            //ARRANGE
            var clientMock = new Mock <IRSAPIClient>();

            clientMock.Setup(x => x.APIOptions).Returns(new APIOptions());
            clientMock
            .Setup(x => x.InstallApplication(It.IsAny <APIOptions>(), It.IsAny <AppInstallRequest>()))
            .Returns(new ProcessOperationResult {
                Success = true, ProcessID = Guid.NewGuid()
            });

            clientMock
            .SetupSequence(x => x.GetProcessState(It.IsAny <APIOptions>(), It.IsAny <Guid>()))
            .Returns(new ProcessInformation {
                State = ProcessStateValue.Running
            })
            .Returns(new ProcessInformation {
                State = ProcessStateValue.Completed
            });


            //ACT
            Test.Helpers.Application.ApplicationHelpers.ImportApplication(clientMock.Object, It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <string>());

            //ASSERT
            clientMock.Verify(c => c.GetProcessState(It.IsAny <APIOptions>(), It.IsAny <Guid>()), Times.AtLeast(2));
        }
예제 #4
0
        public void CompilingProcessTests_ShouldCallRollbackProcess_OnCompileError()
        {
            var syntaxTree = CSharpSyntaxTree.ParseText(@"using System;

namespace ExampleProject
{
    public class Calculator
    {
        public int Subtract(string first, string second)
        {
            return first - second;
        }
    }
}");
            var input      = new MutationTestInput()
            {
                ProjectInfo = new ProjectInfo()
                {
                    ProjectUnderTestAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        Properties = new Dictionary <string, string>()
                        {
                            { "AssemblyTitle", "AssemblyName" },
                        },
                        Resources = new List <ResourceDescription>()
                    },
                    TestProjectAnalyzerResult = new ProjectAnalyzerResult(null, null)
                    {
                        Properties = new Dictionary <string, string>()
                        {
                            { "AssemblyTitle", "AssemblyName" },
                        },
                        Resources = new List <ResourceDescription>()
                    }
                },
                AssemblyReferences = new List <PortableExecutableReference>()
                {
                    MetadataReference.CreateFromFile(typeof(object).Assembly.Location)
                }
            };
            var rollbackProcessMock = new Mock <IRollbackProcess>(MockBehavior.Strict);

            rollbackProcessMock.Setup(x => x.Start(It.IsAny <CSharpCompilation>(), It.IsAny <ImmutableArray <Diagnostic> >(), It.IsAny <bool>()))
            .Returns((CSharpCompilation compilation, ImmutableArray <Diagnostic> diagnostics, bool devMode) =>
                     new RollbackProcessResult()
            {
                Compilation = compilation
            });

            var target = new CompilingProcess(input, rollbackProcessMock.Object);

            using (var ms = new MemoryStream())
            {
                Should.Throw <ApplicationException>(() => target.Compile(new Collection <SyntaxTree>()
                {
                    syntaxTree
                }, ms, false));
            }
            rollbackProcessMock.Verify(x => x.Start(It.IsAny <CSharpCompilation>(), It.IsAny <ImmutableArray <Diagnostic> >(), It.IsAny <bool>()),
                                       Times.AtLeast(2));
        }
예제 #5
0
 public void ConfigureLoggerMiddleware()
 {
     _companyHostBuilderMock.Object.UseCommonModules();
     _appBuilderMock.Verify(
         builder => builder.Use(It.IsAny <Func <RequestDelegate, RequestDelegate> >()), Times.AtLeast(2));
 }
        public void VisaSpelet_borde_visa_två_bilder()
        {
            var ritareMock = new Mock <IRitare>();
            var spelvärld  = SkapaSpelvärld(
                new Objekt {
                Position = new Position(1, 2, 3), Bild = new Bild(new Bildmängdskoordinat(4, 5), new Bildstorlek(6, 7))
            },
                new Objekt {
                Position = new Position(1, 2, 3), Bild = new Bild(new Bildmängdskoordinat(4, 5), new Bildstorlek(6, 7))
            });

            VisaSpelet(ritareMock.Object, spelvärld).Visa();
            ritareMock.Verify(ritare => ritare.KopieraBildTillSkärmen(1, 2, 4, 5, 6, 7), Times.AtLeast(2));
        }
예제 #7
0
        public void TestPrepararPlato()
        {
            var mockBasculaService = new Mock <IBasculaService>();
            var mockCocinaService  = new Mock <ICocinaService>();

            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>()))
            .Returns((Alimento p) => p.Peso);
            mockBasculaService.Setup(bascula => bascula.Pesar(It.IsAny <Alimento>()))
            .Returns((Alimento p) => p.Peso);

            mockCocinaService.Setup(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()))
            .Callback(
                (Alimento p1, Alimento p2)
                =>
            {
                p1.Calentado = true;
                p2.Calentado = true;
            }

                );

            IBasculaService basculaService = mockBasculaService.Object;
            ICocinaService  cocinaService  = mockCocinaService.Object;

            TurbomixService sut        = new TurbomixService(basculaService, cocinaService, null);
            Alimento        mAlimento1 = new Alimento();

            mAlimento1.Nombre = "Curry";
            mAlimento1.Peso   = 1.5F;
            Alimento mAlimento2 = new Alimento();

            mAlimento2.Nombre = "Queso";
            mAlimento1.Peso   = 5F;

            Plato resultado = sut.PrepararPlato(mAlimento1, mAlimento2);

            //Verificaciones
            mockBasculaService.Verify(bascula => bascula.Pesar(It.IsAny <Alimento>()), Times.AtLeast(2));
            mockCocinaService.Verify(cocina => cocina.Calentar(It.IsAny <Alimento>(), It.IsAny <Alimento>()), Times.Once());



            Plato mPlato = new Plato(mAlimento1, mAlimento2);

            Assert.AreEqual(mPlato, resultado);
        }