/// <summary> /// Creates an instance of Attachment /// </summary> /// <returns></returns> private Attachment CreateAttachmentInstance() { string clientId = string.Empty; var clientCreator = new ResourceCreator <Client>(PublicApiAdapter.CreateAdapterForDefaultConnection()); if (PublicAPI.PublicAPISetUp.ListClientId != null && PublicAPISetUp.ListClientId.Count > 0) { clientId = PublicAPISetUp.ListClientId.Random(); } else { clientId = clientCreator.Create(); Assume.That(!string.IsNullOrEmpty(clientId), string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Client")); PublicAPISetUp.ListClientId.Add(clientId); } byte[] byteContent = Util.ReadBinaryFile(Util.GetTestDirectory() + System.IO.Path.DirectorySeparatorChar + DataFolder + System.IO.Path.DirectorySeparatorChar + TxtFilePath); string content = Util.BytesToBase64String(byteContent); Attachment resource = new Attachment { Id = "-1", Resource = ((int)Enums.ResourceType.Client).ToString(), ResourceId = clientId, FileName = "abc.txt", ContentType = Enums.ContentType.Txt, Content = content, }; return(resource); }
public void TestWriteAttachmentPerResource(Enums.ResourceType resourceType) { var attachmentCreator = new ResourceCreator <Attachment>(PublicApiAdapter.CreateAdapterForDefaultConnection()); string attachmentId = attachmentCreator.Create((int)resourceType); Assert.That(!String.IsNullOrEmpty(attachmentId), "Create attachment file failed"); // temporary statement switch (resourceType) { case Enums.ResourceType.Sales: case Enums.ResourceType.Contract: case Enums.ResourceType.Activity: Assert.That(attachmentId, Is.Not.Null.And.Not.Empty, "Create attachment file of resource type {0}", resourceType); break; default: Dictionary <string, object> urlParameters = new Dictionary <string, object>() { { "partition", AuthenticationInfoProvider.Current.DefaultPartition }, { "requestType", "1" }, { "resource", (int)resourceType }, { "id", attachmentId } }; ReadResponseData <Attachment> result = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Attachment>(urlParameters); Assert.That(0 == result.Code, "Read attachment file failed."); Assert.AreEqual(attachmentId, result.Items[0].Id); Assert.AreEqual(((int)resourceType).ToString(), result.Items[0].Resource); break; } }
/// <summary> /// Prepare Attachment Data /// </summary> /// <param name="resourceTypeAttachment">Resource Type</param> /// <param name="resourceEntryId">Resource Id</param> /// <returns>New Attachment Id as string</returns> private string PrepareAttachmentData(int resourceTypeAttachment, string resourceEntryId) { var attachmentCreator = new ResourceCreator <Attachment>(publicApiAdapter); string id = string.Empty; int resourceId = -1; id = attachmentCreator.Create(resourceTypeAttachment, resourceEntryId); bool parsed = Int32.TryParse(id, out resourceId); Assume.That(parsed); Assume.That(resourceId > 0, "The resource(" + resourceTypeAttachment + ")" + " can not create!!!!!"); return(id); }
public void TestWriteAttachmentFilename(int expectResultCode, string fileName) { var clientCreator = new ResourceCreator <Client>(PublicApiAdapter.CreateAdapterForDefaultConnection()); int resourceType = (int)Enums.ResourceType.Client; string resourceId = clientCreator.Create(); Assert.That(!String.IsNullOrEmpty(resourceId)); Attachment attachment = new Attachment() { Id = "-1", Resource = resourceType.ToString(), ResourceId = resourceId, FileName = fileName, ContentType = Enums.ContentType.Txt, Content = "VGV4dCBjb250ZW50", }; if (expectResultCode == Enums.PublicAPIResultCode.Success) { string id = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteSuccess(attachment, null); int attachmentId = Int32.Parse(id); Dictionary <string, object> urlParameters = new Dictionary <string, object>() { { "partition", AuthenticationInfoProvider.Current.DefaultPartition }, { "requestType", "1" }, { "resource", resourceType }, { "resourceId", resourceId } }; ReadResponseData <Attachment> readResult = PublicApiAdapter.CreateAdapterForDefaultConnection().ReadSuccess <Attachment>(urlParameters); Assert.That(0 == readResult.Code, "Read response data failed."); Assert.AreEqual(1, readResult.Count); Assert.AreEqual(resourceType.ToString(), readResult.Items[0].Resource); Assert.AreEqual(resourceId, readResult.Items[0].ResourceId); Assert.AreEqual(attachmentId.ToString(), readResult.Items[0].Id); Assert.AreEqual(fileName, readResult.Items[0].FileName); } else { // TODO: should be unified. string or int // Assert.AreEqual(expectResultCode, writeResultXml.Code, "wrong result code."); ErrorCode result = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteFail(attachment, cleanupAction: null); Assert.AreEqual(expectResultCode, result.Code, "Wrong result code."); } }
/// <summary> /// Creates a new Candidate /// </summary> /// <returns></returns> private string PrepareCandidate() { var publicApiAdapter = PublicApiAdapter.CreateAdapterForDefaultConnection(); var candidateCreator = new ResourceCreator <Candidate>(publicApiAdapter); string candidateId = string.Empty; if (PublicAPISetUp.ListCandidateId.Count > 0) { candidateId = PublicAPISetUp.ListCandidateId.Random(); } else { candidateId = candidateCreator.Create(); Assume.That(!string.IsNullOrEmpty(candidateId)); PublicAPISetUp.ListCandidateId.Add(candidateId); } return(candidateId); }
public void TestUpdateCandidateMultipleLineNumberCharacters(int numChar) { var publicApiAdapter = PublicApiAdapter.CreateAdapterForDefaultConnection(); var candidateCreator = new ResourceCreator <Candidate>(publicApiAdapter); string candidateId = string.Empty; if (PublicAPISetUp.ListCandidateId.Count > 0) { candidateId = PublicAPISetUp.ListCandidateId.Random(); } else { candidateId = candidateCreator.Create(); Assume.That(!string.IsNullOrEmpty(candidateId), string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Candidate")); PublicAPISetUp.ListCandidateId.Add(candidateId); } string memo = Util.GetUniqueString(numChar, false); Candidate resource = new Candidate { Id = candidateId, Memo = memo, }; candidateId = publicApiAdapter.WriteSuccess(resource, null); int resourceId = -1; bool parsed = Int32.TryParse(candidateId, out resourceId); Assert.IsTrue(parsed); Assert.IsTrue(resourceId > 0, string.Format(Enums.Message.UPDATE_RESOURCE_ENTRY_FAILED, "Candidate")); //Verify data Dictionary <string, object> fields = new Dictionary <string, object>() { { "Person.P_Memo", resource.Memo }, }; VerifyFieldData(resourceId, fields); }
private string PrepareClient() { var publicApiAdapter = PublicApiAdapter.CreateAdapterForDefaultConnection(); var clientsCreator = new ResourceCreator <Client>(publicApiAdapter); string id = string.Empty; if (PublicAPISetUp.ListClientId.Count > 0) { id = PublicAPISetUp.ListClientId.Random(); } else { id = clientsCreator.Create(); int resourceId = -1; bool parsed = Int32.TryParse(id, out resourceId); Assume.That(parsed); Assume.That(resourceId > 0, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Activity")); PublicAPISetUp.ListClientId.Add(id); } return(id); }
public void TestUpdateCandidate(string fieldName, object fieldValue) { var publicApiAdapter = PublicApiAdapter.CreateAdapterForDefaultConnection(); var candidateCreator = new ResourceCreator <Candidate>(publicApiAdapter); string candidateId = string.Empty; if (PublicAPISetUp.ListCandidateId.Count > 0) { candidateId = PublicAPISetUp.ListCandidateId.Random(); } else { candidateId = candidateCreator.Create(); Assume.That(!string.IsNullOrEmpty(candidateId), string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Candidate")); PublicAPISetUp.ListCandidateId.Add(candidateId); } Candidate candidate = new Candidate() { Id = candidateId }; candidate.DictionaryValues[fieldName] = fieldValue; string id = publicApiAdapter.WriteSuccess(candidate, null); int resourceId = -1; bool parsed = Int32.TryParse(id, out resourceId); Assert.IsTrue(parsed); Assert.IsTrue(resourceId > 0, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Candidate")); Dictionary <string, object> fields = new Dictionary <string, object>() //{ { fieldName.Split('.')[1], fieldValue } }; { { fieldName, fieldValue } }; VerifyFieldData(resourceId, fields); }
public IEnumerable <App> Create() { foreach (var component in ComponentRepository.GetAll()) { foreach (var type in AppTypeProvider.GetTypes(component)) { var attribute = CustomAttributeExtensions.GetCustomAttribute <AppAttribute>(type); var translationAttribute = CustomAttributeExtensions.GetCustomAttribute <TranslationsAttribute>(type); var translations = translationAttribute != null?TranslationRepositoryCreator.Create(component.Id + "/" + translationAttribute.Path) : new EmptyTranslationRepository(); yield return(new App( attribute.Id, component, scripts: ScriptCreator.Create(component.Id, type), styles: StyleCreator.Create(component.Id, type), resources: ResourceCreator.Create(component.Id, type), translations: translations )); } } }
private ActionResult CreateResource(string container, string file, bool isDirectory, string contents, bool rewriteFile = false) { try { var resource = new ResourceCreator { Container = container, File = file, IsDirectory = isDirectory, Contents = contents, Rewrite = rewriteFile }; resource.Create(this.Tenant); } catch (ResourceCreateException ex) { return(this.Failed(ex.Message, HttpStatusCode.InternalServerError)); } return(this.Ok()); }
public void TestUpdateCandidateWithPhase() { var publicApiAdapter = PublicApiAdapter.CreateAdapterForDefaultConnection(); var candidateCreator = new ResourceCreator <Candidate>(publicApiAdapter); string candidateId = string.Empty; if (PublicAPISetUp.ListCandidateId.Count > 0) { candidateId = PublicAPISetUp.ListCandidateId.Random(); } else { candidateId = candidateCreator.Create(); Assume.That(!string.IsNullOrEmpty(candidateId), string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Candidate")); PublicAPISetUp.ListCandidateId.Add(candidateId); } Candidate candidate = new Candidate() { Id = candidateId, Phase = new Option() { ActualXMLTag = OptionFieldHelper.GetOptionList(Enums.Options.CandidatePhase).Random() }, PhaseDate = Util.ToString(DateTime.Now) }; candidateId = PublicApiAdapter.CreateAdapterForDefaultConnection().WriteSuccess(candidate, null); Assert.That(candidateId, Is.Not.Null.And.Not.Empty, string.Format(Enums.Message.CREATE_RESOURCE_ENTRY_FAILED, "Candidate")); Dictionary <string, object> fields = new Dictionary <string, object>(); fields.Add("Person.P_Phase", (candidate.Phase as Option).ActualXMLTag); VerifyFieldData(int.Parse(candidateId), fields); }
public void TestReCreate() { var response = ResourceCreator.Create(new CartCreateResource()); AssertBadRequestReason(response, BadRequestReason.SameExists); }