public void Static_CreateOrRepo_with_invalid_ServiceProvider()
 {
     //arrange
     //act
     //assert
     Assert.Throws <ArgumentNullException>(() => ServiceRepo.CreateOrRepo(null));
 }
        public void Static_CreateOrRepo_with_custom_ServiceProvider()
        {
            //arrange
            var pro = new Mock <IServiceProvider>();

            //act
            var svcPro = ServiceRepo.CreateOrRepo(pro.Object);

            //assert
            Assert.NotNull(svcPro);
            Assert.Same(svcPro, ServiceRepo.Instance);
        }
        public void Static_CreateOrRepo_expect_override_behaviour()
        {
            //arrange
            var pro             = new Mock <IServiceProvider>();
            var workflowRuntime = new Mock <IWorkflowHost <TaskRuntime> >().Object;

            pro.Setup(p => p.GetService(It.Is <Type>(t => t == typeof(IWorkflowHost <TaskRuntime>)))).Returns(workflowRuntime).Verifiable();

            //act
            var svcPro = ServiceRepo.CreateOrRepo(pro.Object);

            var svcWorkflow        = ServiceRepo.Instance.GetServiceOf <IWorkflowHost <TaskRuntime> >();
            var svcWorkflowAnother = ServiceRepo.Instance.GetService(typeof(IWorkflowHost <TaskRuntime>));

            //assert
            Assert.NotNull(svcPro);
            Assert.Same(svcPro, ServiceRepo.Instance);
            Assert.Same(workflowRuntime, svcWorkflow);
            Assert.Same(workflowRuntime, svcWorkflowAnother);
            pro.Verify(p => p.GetService(It.Is <Type>(t => t == typeof(IWorkflowHost <TaskRuntime>))),
                       Times.Exactly(2));
        }
        public void Static_CreateOrRepo_with_valid_ServiceProvider()
        {
            //arrange
            var pro = new Mock <IServiceProvider>();
            var id  = Helper.GetJobId();
            var job = Helper.GetFakeJob().Object;

            pro.Setup(p => p.GetService(It.Is <Type>(t => t == typeof(JobId)))).Returns(id).Verifiable();
            pro.Setup(p => p.GetService(It.Is <Type>(t => t == typeof(IFakeJob)))).Returns(job).Verifiable();

            //act
            var svcPro = ServiceRepo.CreateOrRepo(pro.Object);

            var svcId  = ServiceRepo.Instance.GetServiceOf <JobId>();
            var svcJob = ServiceRepo.Instance.GetServiceOf <IFakeJob>();

            //assert
            Assert.NotNull(svcPro);
            Assert.Same(svcPro, ServiceRepo.Instance);
            Assert.NotNull(svcId);
            Assert.NotNull(svcJob);
            Assert.Same(svcId, id);
            Assert.Same(svcJob, job);
        }