public void SiteId() { var user = InMemoryUser.TestInstance(); user.Login = "******"; user.SiteId = "testsite"; string result = qb.ConvertAllValues("status='WAPPR' and reportedby=@username and siteid='@usersite'", user); Assert.AreEqual("status='WAPPR' and reportedby='test' and siteid='testsite'", result); }
public void TestUserGenericProperties() { var user = InMemoryUser.TestInstance(); user.Genericproperties.Add("siteid", "a1"); user.Genericproperties.Add("orgid", "a2"); var result = qb.ConvertAllValues("[email protected]['siteid'] and [email protected]['orgid']", user); Assert.AreEqual("sr.siteid=a1 and sr.orgid=a2", result); }
public void TestWebMenuParsing() { foreach (var clientName in TestUtil.ClientNames()) { Debug.WriteLine(clientName); ApplicationConfiguration.TestclientName = clientName; MetadataProvider.StubReset(); var menu = InMemoryUser.TestInstance("test").Menu(ClientPlatform.Web); Assert.IsNotNull(menu); } }
public static InMemoryUser CurrentUser(Boolean fetchFromDB = true, bool throwAnonymousException = true) { if (ApplicationConfiguration.IsUnitTest) { return(InMemoryUser.TestInstance("test")); } var currLogin = LogicalThreadContext.GetData <string>("user") ?? CurrentPrincipalLogin; if (currLogin == "") { if (!throwAnonymousException) { return(new InMemoryUser { Login = "******" }); } throw new UnauthorizedAccessException(); } if (!fetchFromDB || currLogin == null || _users.ContainsKey(currLogin)) { return(_users[currLogin]); } //cookie authenticated already //TODO: remove this in prod? var dbUser = new SWDBHibernateDAO().FindSingleByQuery <User>(User.UserByUserName, currLogin); if (dbUser == null) { throw new InvalidOperationException("user should exist at DB"); } var formsIdentity = CurrentPrincipal.Identity as System.Web.Security.FormsIdentity; var timezone = String.Empty; if (formsIdentity != null && formsIdentity.Ticket != null && !String.IsNullOrWhiteSpace(formsIdentity.Ticket.UserData)) { var userData = PropertyUtil.ConvertToDictionary(formsIdentity.Ticket.UserData); timezone = userData["userTimezoneOffset"]; } UserFound(dbUser, timezone); return(_users[currLogin]); }
public void IncidentHardwareReport() { var dto = new SearchRequestDto(); dto.AppendProjectionField(ProjectionField.Default("asset_assetloccomm_commoditiesownedby_.description")); dto.AppendProjectionField(ProjectionField.Default("asset_assetloccomm_.commodity")); var completeOne = MetadataProvider.Application("incident"); var metadata = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("hardwarerepair"), InMemoryUser.TestInstance(), ClientPlatform.Web); ApplicationSchemaDefinition schema; var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("incident"), metadata.Schema); var result = QueryFromBuilder.Build(sliced, dto); Assert.AreEqual("from incident as incident left join asset as asset_ on (incident.assetnum = asset_.assetnum and incident.siteid = asset_.siteid)left join assetloccomm as asset_assetloccomm_ on (asset_.assetnum = asset_assetloccomm_.assetnum and asset_.siteid = asset_assetloccomm_.siteid)left join commodities as asset_assetloccomm_commoditiesownedby_ on (asset_assetloccomm_.commodity = asset_assetloccomm_commoditiesownedby_.commodity and asset_assetloccomm_.itemsetid = asset_assetloccomm_commoditiesownedby_.itemsetid and (asset_assetloccomm_commoditiesownedby_.description like 'Asset owened by%'))", result); }
public void ChangeSRUnionSearch() { var dto = new SearchRequestDto(); var completeOne = MetadataProvider.Application("srforchange"); var metadata = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("changeunionschema"), InMemoryUser.TestInstance(), ClientPlatform.Web); ApplicationSchemaDefinition schema; var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("srforchange"), metadata.Schema); var result = QueryFromBuilder.Build(sliced, dto); Assert.AreEqual("from SR as srforchange left join asset as asset_ on (srforchange.assetnum = asset_.assetnum and srforchange.siteid = asset_.siteid)", result); }
private static void DoTest(string schemaId, string input, string output) { var appMetadata = MetadataProvider.Application("imac") .ApplyPolicies(new ApplicationMetadataSchemaKey(schemaId), InMemoryUser.TestInstance("test"), ClientPlatform.Web); var metadata = MetadataProvider.Entity("imac"); var imacjson = JObject.Parse(new StreamReader("jsons\\imac\\" + input).ReadToEnd()); var imac = EntityBuilder.BuildFromJson <CrudOperationData>(typeof(CrudOperationData), metadata, null, imacjson, null); var resultDescription = ImacDescriptionHandler.BuildDescription(imac, appMetadata); Debug.Write(resultDescription); var expectedResult = new StreamReader("jsons\\imac\\descriptionresults\\" + output).ReadToEnd(); expectedResult = expectedResult.Replace("\r\n", "\n"); resultDescription = resultDescription.Replace("\r\n", "\n"); Assert.AreEqual(expectedResult, resultDescription); }
public void TestAddWorkLogToIncident() { ApplicationConfiguration.TestclientName = "gric"; MetadataProvider.StubReset(); var metadata = MetadataProvider.Entity("SR"); var completeApp = MetadataProvider.Application("servicerequest"); var sliced = MetadataProvider.SlicedEntityMetadata(completeApp.ApplyPolicies( new ApplicationMetadataSchemaKey("editdetail"), InMemoryUser.TestInstance("test"), ClientPlatform.Web)); var attributes = sliced.NonListAssociations(); Assert.IsTrue(attributes.Count(a => a.Qualifier == "asset_") == 1); }
public void ChangeSRUnionSearch() { var dto = new SearchRequestDto(); dto.BuildUnionDTO(dto, MetadataProvider.FindSchemaDefinition("change.list")); var completeOne = MetadataProvider.Application("change"); var metadata = completeOne.ApplyPolicies(new ApplicationMetadataSchemaKey("list"), InMemoryUser.TestInstance(), ClientPlatform.Web); ApplicationSchemaDefinition schema; var sliced = SlicedEntityMetadataBuilder.GetInstance(MetadataProvider.Entity("wochange"), metadata.Schema, 300); var result = QuerySelectBuilder.BuildSelectAttributesClause(sliced.UnionSchema, QueryCacheKey.QueryMode.Union, dto.unionDTO); Assert.AreEqual("select null, null, null, null, '-666' as zeroedattr, srforchange.description as hlagchangesummary, srforchange.ticketid as ticketid, asset_.description as asset_description, null, null, CASE WHEN srforchange.PLUSPCUSTOMER IS NOT NULL AND srforchange.PLUSPCUSTOMER = 'HLC-00' then 'HLAG' WHEN srforchange.PLUSPCUSTOMER IS NOT NULL AND LENGTH(srforchange.PLUSPCUSTOMER) >= 3 THEN SUBSTR(srforchange.PLUSPCUSTOMER, LENGTH(srforchange.PLUSPCUSTOMER) - 2, 3) ELSE '' END as hlagpluspcustomer, CASE WHEN LOCATE('@',srforchange.REPORTEDBY) > 0 THEN SUBSTR(srforchange.REPORTEDBY,1,LOCATE('@',srforchange.REPORTEDBY)-1) ELSE srforchange.REPORTEDBY END as hlagreportedby, srforchange.status as status ", result); }
public void TestNestedGetAttribute() { ApplicationConfiguration.TestclientName = "hapag"; MetadataProvider.StubReset(); var appMetadata = MetadataProvider.Application("imac").ApplyPolicies(new ApplicationMetadataSchemaKey("install"), InMemoryUser.TestInstance("test"), ClientPlatform.Web); var metadata = MetadataProvider.Entity("imac"); var incident = JObject.Parse(new StreamReader("jsons\\sr\\updateasset.json").ReadToEnd()); var entity = EntityBuilder.BuildFromJson <Entity>(typeof(Entity), metadata, appMetadata, incident, null); var assetRel = entity.GetRelationship("asset_") as Entity; Assert.IsNotNull(assetRel); var primaryUser = assetRel.GetRelationship("primaryuser_") as Entity; Assert.IsNotNull(primaryUser); var personId = primaryUser.GetAttribute("personid"); Assert.AreEqual(entity.GetAttribute("asset_.primaryuser_.personid"), personId); }
public void TestAddWorkLogToIncident() { ApplicationConfiguration.TestclientName = "hapag"; MetadataProvider.StubReset(); var imac = MetadataProvider.Entity("imac"); var metadata = MetadataProvider.Entity("incident"); var completeApp = MetadataProvider.Application("incident"); var sliced = MetadataProvider.SlicedEntityMetadata(completeApp.ApplyPolicies(new ApplicationMetadataSchemaKey("detail"), InMemoryUser.TestInstance("test"), ClientPlatform.Web)); var attributes = sliced.Attributes(EntityMetadata.AttributesMode.NoCollections); var entityAttributes = attributes as EntityAttribute[] ?? attributes.ToArray(); Assert.IsNull(entityAttributes.FirstOrDefault(a => a.Name == "asset_.eq23")); Assert.IsNotNull(entityAttributes.FirstOrDefault(a => a.Name == "asset_.description")); var incident = JObject.Parse(new StreamReader("jsons\\incident\\test1.json").ReadToEnd()); var entity = EntityBuilder.BuildFromJson <Entity>(typeof(Entity), metadata, null, incident, null); Assert.IsNull(entity.GetAttribute("wonum")); var solution = entity.GetRelationship("solution") as Entity; Assert.IsNotNull(solution); var cause = solution.GetRelationship("cause") as Entity; Assert.IsNotNull(cause); Assert.IsNull(cause.GetAttribute("ldtext")); var symptom = solution.GetRelationship("symptom") as Entity; Assert.IsNotNull(symptom); Assert.IsNotNull(symptom.GetAttribute("ldtext")); }
private static void DoTest(string schemaId, string input, string output) { var appMetadata = MetadataProvider.Application("offering") .ApplyPolicies(new ApplicationMetadataSchemaKey(schemaId), InMemoryUser.TestInstance("test"), ClientPlatform.Web); var metadata = MetadataProvider.Entity("offering"); var imacjson = JObject.Parse(new StreamReader("jsons\\offering\\" + input).ReadToEnd()); var offeringData = EntityBuilder.BuildFromJson <CrudOperationData>(typeof(CrudOperationData), metadata, null, imacjson, null); offeringData.ApplicationMetadata = appMetadata; var resultDescription = HapagOfferingLongDescriptionHandler.ParseSchemaBasedLongDescription(offeringData); Debug.Write(resultDescription); var expectedResult = new StreamReader("jsons\\offering\\descriptionresults\\" + output).ReadToEnd(); Assert.AreEqual(expectedResult, resultDescription); }