private Exception ThreadedScopeThreadRun(ManualResetEvent set, ManualResetEvent wait) { try { var container = new IoCContainer(); AmDisposable disp; using (var scope = new IoCScope()) { disp = container.GetInstance <AmDisposable>(); Assert.Equal(0, disp.DisposeCalled); Assert.Equal(1, scope.InstanceCount); set.Set(); wait.WaitOne(); Assert.Equal(1, scope.InstanceCount); var disp2 = container.GetInstance <AmDisposable>(); Assert.Same(disp, disp2); Assert.Equal(1, scope.InstanceCount); } Assert.Equal(1, disp.DisposeCalled); } catch (Exception exception) { return(exception); } return(null); }
public MovimentoController() { var container = new IoCContainer().GetContainer(); _movimentoService = container.GetInstance <IMovimentoService>(); _produtoService = container.GetInstance <IProdutoService>(); _cosifService = container.GetInstance <ICosifService>(); }
public void SingleScope() { var container = new IoCContainer(); AmDisposable disp; using (new IoCScope()) { disp = container.GetInstance <AmDisposable>(); Assert.Equal(0, disp.DisposeCalled); var disp2 = container.GetInstance <AmDisposable>(); Assert.Same(disp, disp2); } Assert.Equal(1, disp.DisposeCalled); }
public void Services_Validate_Required_Failed() { FormPackage6.Core.DomainModel.Form.Form formModel = new FormPackage6.Core.DomainModel.Form.Form(); Field field = new Field() { FieldType = new FieldType() { Type = "TextBox" }, Name = "Text", Id = "0001", Value = String.Empty, Mandatory = true }; formModel.Fields = new List <Field>(); formModel.Fields.Add(field); IFormService formService = IoCContainer.GetInstance <IFormService>(); var result = formService.Validate(formModel, null); Assert.IsNotNull(result.Errors.FirstOrDefault(x => x.FieldId == field.Id && x.ErrorType == "require")); }
public void FormPlugin_Services_Get_Field_Empty() { var formPluginService = IoCContainer.GetInstance <IFormPluginService>(); var result = formPluginService.GetFields(0, ""); Assert.IsTrue(result.Count() == 0); }
public void Form_Integration_Services_Get_Dictionary_Empty() { IoCContainer.Configure(x => x.For <IUmbracoService>().Use(new Mock <IUmbracoService>().Object)); var service = IoCContainer.GetInstance <IIntegrationService>(); Message message = new Message(); var result = service.GetKeyFromDictionary(message); Assert.IsTrue(string.IsNullOrEmpty(result.Description)); }
public void Form_Integration_Services_Get_Dictionary_Null() { IoCContainer.Configure(x => x.For <IUmbracoService>().Use(new Mock <IUmbracoService>().Object)); var service = IoCContainer.GetInstance <IIntegrationService>(); Message message = null; var result = service.GetKeyFromDictionary(message); Assert.IsNull(result); }
public object GetService(Type serviceType) { if (serviceType.IsAbstract || serviceType.IsInterface) { return(Container.TryGetInstance(serviceType)); } else { return(Container.GetInstance(serviceType)); } }
public void MustBeScoped() { var container = new IoCContainer(); container.Register <ICoreCalculator, CoreCalculator>() .MustBeScoped(); var exception = Assert.Throws <InvalidOperationException>(() => { var calc = container.GetInstance <ICoreCalculator>(); Assert.NotNull(calc); }); Assert.Contains("could not be created since it requires a scope", exception.Message); }
public async Task TestRepository() { CsvConfig <Account> .OmitHeaders = true; var context = IoCContainer.GetInstance <IInMemoryCsvRepository>(); context.FileName = "accountInformation.csv"; Assert.IsNotNull(context); var randomData = GetFakeData(); await context.Save(randomData); var data = await context.Get(); Assert.IsNotNull(data); Assert.IsTrue(data.Count() == 100); }
public void CreateDependentInstance() { var container = new IoCContainer(); container.Register <ICoreCalculator, CoreCalculator>(); container.Register <ICoreValidator>(new CoreValidator(4)); container.Register(CoreConfig.Default); container.Register <ICommandEvents, EmptyCommandEvents>(); var core = container.GetInstance <Core>(); Assert.Null(core.Initializer); Assert.NotNull(core.Events); core.Calculate(4, 6, 5); }
public void NestedScope() { var container = new IoCContainer(); AmDisposable disp; using (new IoCScope()) { disp = container.GetInstance <AmDisposable>(); Assert.Equal(0, disp.DisposeCalled); var disp2 = container.GetInstance <AmDisposable>(); Assert.Same(disp, disp2); AmDisposable disp3; using (new IoCScope()) { disp3 = container.GetInstance <AmDisposable>(); Assert.NotSame(disp, disp3); var disp4 = container.GetInstance <AmDisposable>(); Assert.Same(disp3, disp4); } Assert.Equal(1, disp3.DisposeCalled); } Assert.Equal(1, disp.DisposeCalled); }
public void Form_Integration_Services_Get_Dictionary_Corret() { Message message = new Message(); message.Description = "Description"; message.Key = "Key"; var umbService = new Mock <IUmbracoService>(); umbService.Setup(x => x.GetDictionaryItem(message.Key, message.Description)).Returns(message.Description); IoCContainer.Configure(x => x.For <IUmbracoService>().Use(umbService.Object)); var service = IoCContainer.GetInstance <IIntegrationService>(); var result = service.GetKeyFromDictionary(message); Assert.IsTrue(result.Description.Equals(message.Description)); }
public async Task TestContext() { CsvConfig <Account> .OmitHeaders = true; var context = IoCContainer.GetInstance <IInMemoryAccountContext>(); Assert.IsNotNull(context); var randomData = GetFakeData(); await context.SaveData("accountInformation.csv", randomData); var data = await context.GetData("accountInformation.csv"); Assert.IsNotNull(data); Assert.IsTrue(data.Count() == 100); var randomData2 = GetFakeData(); await context.SaveData("accountInformation2.csv", randomData2); var data2 = await context.GetData("accountInformation2.csv"); Assert.IsNotNull(data2); Assert.IsTrue(data2.Count() == 100); }
public void Services_UploadFiles_Failed() { FormPackage6.Core.DomainModel.Form.Form formModel = new FormPackage6.Core.DomainModel.Form.Form(); Field field = new Field() { FieldType = new FieldType() { Type = FormPackage6.Core.Alias.PropertyAlias.Upload }, Name = "Text", Id = "0001", Value = String.Empty, Mandatory = true }; formModel.Fields = new List <Field>(); formModel.Fields.Add(field); List <FileViewModel> uploadedFiles = new List <FileViewModel>(); var file = new Mock <HttpPostedFileBase>(); file.Setup(x => x.FileName).Returns("test.jpg"); file.Setup(x => x.ContentType).Returns("PDF"); FileViewModel fileModel = new FileViewModel() { file = file.Object, name = field.Id }; uploadedFiles.Add(fileModel); IFormService formService = IoCContainer.GetInstance <IFormService>(); formService.SaveUploadFiles(ref formModel, uploadedFiles); mediaService.Verify(x => x.Save(It.IsAny <IMedia>(), 0, true)); }
public void Services_Validate_Email_OK() { FormPackage6.Core.DomainModel.Form.Form formModel = new FormPackage6.Core.DomainModel.Form.Form(); Field field = new Field() { FieldType = new FieldType() { Type = FormPackage6.Core.Alias.PropertyAlias.Email }, Value = "*****@*****.**" }; formModel.Fields = new List <Field>(); formModel.Fields.Add(field); IFormService formService = IoCContainer.GetInstance <IFormService>(); var result = formService.Validate(formModel, null); Assert.AreEqual(result.Message, "success"); }
public void Services_Validate_Email_Failed() { FormPackage6.Core.DomainModel.Form.Form formModel = new FormPackage6.Core.DomainModel.Form.Form(); Field field = new Field() { FieldType = new FieldType() { Type = FormPackage6.Core.Alias.PropertyAlias.Email }, Name = "Email", Id = "0001", Value = "email.com" }; formModel.Fields = new List <Field>(); formModel.Fields.Add(field); IFormService formService = IoCContainer.GetInstance <IFormService>(); var result = formService.Validate(formModel, null); Assert.IsNotNull(result.Errors.FirstOrDefault(x => x.FieldId == field.Id && x.ErrorType == "format")); }
public void Services_Validate_Required_OK() { FormPackage6.Core.DomainModel.Form.Form formModel = new FormPackage6.Core.DomainModel.Form.Form(); Field field = new Field() { FieldType = new FieldType() { Type = "TextBox" }, Name = "Text", Id = "0001", Value = "Something", Mandatory = true }; formModel.Fields = new List <Field>(); formModel.Fields.Add(field); IFormService formService = IoCContainer.GetInstance <IFormService>(); var result = formService.Validate(formModel, null); Assert.AreEqual(result.Message, "success"); }