public void ChangecsdUserPasswordWithValidDataApiTest() { var expectedNewPassword = "******"; Thread.Sleep(100); var user = new UserConstructor(); var createdUser = AuthRequests.SendRequestClientSignUpPost(user.User); var responseModel = ClientRequests.SendRequestChangeClientPasswordPost( "QWE123qwe!@#", expectedNewPassword, createdUser.TokenData.Token); Assert.Multiple(() => { Assert.AreEqual(createdUser.TokenData.Token, responseModel.Model.Token); Assert.AreEqual(HttpStatusCode.OK, responseModel.Response.StatusCode); }); }
public void ChangeUserComopanyLocationyApiTest() { var expectedLocationName = "New York"; var expectedLocationTimezone = "America/New_York"; var user = new UserConstructor(); var createdUser = AuthRequests.SendRequestClientSignUpPost(user.User); var responseModel = ClientRequests.SendRequestChangeClientProfileInfoPatch( createdUser.User.ClientProfile.Industry, expectedLocationName, expectedLocationTimezone, createdUser.TokenData.Token); Assert.Multiple(() => { Assert.AreEqual(expectedLocationName, responseModel.Model.LocationName); Assert.AreEqual(expectedLocationTimezone, responseModel.Model.LocationTimezone); Assert.AreEqual(HttpStatusCode.OK, responseModel.Response.StatusCode); }); }
public void ChangeUserSelfInfoApiTest() { var expectedFirstName = "Sunny"; var expectedLastName = "Smith"; var user = new UserConstructor(); var createdUser = AuthRequests.SendRequestClientSignUpPost(user.User); var responseModel = ClientRequests.SendRequestChangeClientSelfInfoPatch( expectedFirstName, expectedLastName, createdUser.TokenData.Token); Assert.Multiple(() => { Assert.AreEqual(expectedFirstName, responseModel.Model.FirstName); Assert.AreEqual(expectedLastName, responseModel.Model.LastName); Assert.AreEqual(HttpStatusCode.OK, responseModel.Response.StatusCode); }); }
private UserConstructor DefineConstructor(UserType type, List <string> modifiers, String[] parTypes, String[] parNames) { MethodAttributes attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName; foreach (String s in modifiers) { attr |= (MethodAttributes)Enum.Parse(typeof(MethodAttributes), s, true); } IdEntry[] pars = new IdEntry[parTypes.Length]; for (int i = 0; i < parTypes.Length; i++) { pars[i] = this.GetTypeIdEntry(parTypes[i]); } UserConstructor cb = type.DefineConstructor(attr, pars, parNames); return(cb); }
public void ChangeUserProfileCompanyInfoWithValidDataApiTest() { var expectedCompanyName = "Sunny Jonson"; var expectedCompanyURL = "http://sunnyJonson.com"; var expectedCompanyDescription = "somthing"; var user = new UserConstructor(); var createdUser = AuthRequests.SendRequestClientSignUpPost(user.User); var userWithProfileCompanyInfo = ClientRequests.SendRequestClientProfileCompanyInfoPatch(createdUser); var responseModel = ClientRequests.SendRequestChangeClientProfileCompanyInfoPatch( expectedCompanyDescription, expectedCompanyName, expectedCompanyURL, userWithProfileCompanyInfo.TokenData.Token); Assert.Multiple(() => { Assert.AreEqual(expectedCompanyName, responseModel.Model.CompanyName); Assert.AreEqual(expectedCompanyURL, responseModel.Model.CompanyWebsite); Assert.AreEqual(expectedCompanyDescription, responseModel.Model.CompanyDescription); Assert.AreEqual(HttpStatusCode.OK, responseModel.Response.StatusCode); }); }
public override void OnResponse(BinaryReader reader) { uint code = reader.ReadUInt32(); System.Diagnostics.Debug.WriteLine("code: " + code.ToString("x")); ; if (code == 0x4e32b894) // config constructor { ConfigConstructor config = new ConfigConstructor(); config.Read(reader); ConfigConstructor = config; } else if (code == 0xff036af1) // auth.authorization :/ { Auth_authorizationConstructor auth = new Auth_authorizationConstructor(); auth.Read(reader); UserConstructor = (UserConstructor)auth.user; } else // TODO something didn't go right... { if (code == 0xb446ae3) // messages slice still? { var result = TL.Parse(reader, code); ; } else { try { while (true) { reader.ReadUInt32(); // flush reader, it's the best we can do! } } catch (EndOfStreamException) { } } } }
/// <summary> /// To be called after WalkTypes(TreeNode). This method walks all classes and defines its methods and fields /// </summary> public void WalkTypeMembers() { // now define all methods and fields of the classes int interfaces = 0; Dictionary <TypeBuilder, UserType> hasConstructors = new Dictionary <TypeBuilder, UserType>(); for (int i = 0; i < types.Count; i++) { TreeNode n = types[i]; UserType customType = usertypes[i]; TypeBuilder tb = (TypeBuilder)n.Entry.ReflectionObject; Type b; if (customType.BaseType is UserType) { b = (Type)((UserType)customType.BaseType).Entry.ReflectionObject; } else { b = customType.BaseType; } if (!tb.IsInterface) { tb.SetParent(b); } foreach (Type t in customType.GetDirectInterfaces()) { tb.AddInterfaceImplementation(t); } int index = allTypes.IndexOf(tb.BaseType as TypeBuilder); if (index != -1 && index > allTypes.IndexOf(tb)) { TypeBuilder tb2 = (TypeBuilder)tb.BaseType; allTypes.Remove(tb2); allTypes.Insert(allTypes.IndexOf(tb), tb2); } else if (tb.IsInterface && tb.GetInterfaces().Length > 0 && allTypes.IndexOf(tb.GetInterfaces()[0] as TypeBuilder) > allTypes.IndexOf(tb)) { TypeBuilder tb2 = (TypeBuilder)tb.GetInterfaces()[0]; allTypes.Remove(tb2); allTypes.Insert(allTypes.IndexOf(tb), tb2); interfaces++; } else if (tb.IsInterface) { allTypes.Remove(tb); allTypes.Insert(interfaces, tb); interfaces++; } Boolean hasConstructor = false; int enumCount = 0; foreach (TreeNode n2 in n.Children) { if (n2.Type == VnvdTreeWalker.FIELD) { UserField uf = (UserField)n2.Entry.ReflectionObject; n2.Entry.ReflectionObject = DefineField(tb, uf.Name, uf.Attributes, uf.FieldType); } else if (n2.Type == VnvdTreeWalker.CONSTRUCTOR) { hasConstructor = true; UserConstructor uf = (UserConstructor)n2.Entry.ReflectionObject; n2.Entry.ReflectionObject = DefineConstructor(tb, uf.Attributes, uf.GetParameters()); } else if (n2.Type == VnvdTreeWalker.METHOD) { UserMethod uf = (UserMethod)n2.Entry.ReflectionObject; n2.Entry.ReflectionObject = DefineMethod(tb, uf.Name, uf.Attributes, uf.ReturnType, uf.GetParameters()); } else if (n2.Type == VnvdTreeWalker.IMETHOD) { UserMethod uf = (UserMethod)n2.Entry.ReflectionObject; n2.Entry.ReflectionObject = DefineMethod(tb, uf.Name, uf.Attributes, uf.ReturnType, uf.GetParameters()); } else if (n2.Type == VnvdTreeWalker.SCONSTRUCTOR) { //UserConstructor uf = (UserConstructor)n2.Entry.ReflectionObject; n2.Entry.ReflectionObject = tb.DefineTypeInitializer(); } else if (n2.Type == VnvdTreeWalker.ENUMOPTION) { UserField uf = (UserField)n2.Entry.ReflectionObject; FieldBuilder fb = tb.DefineField(uf.Name, tb, FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Public); n2.Entry.ReflectionObject = fb; fb.SetConstant(enumCount); enumCount++; } } if (tb.IsClass && !tb.IsEnum && !hasConstructor) { hasConstructors[tb] = customType; } } foreach (TypeBuilder t in allTypes) { if (hasConstructors.ContainsKey(t)) { UserConstructor uc = (UserConstructor)hasConstructors[t].GetConstructor(new Type[] { }); UserType baset = FindUserType(hasConstructors[t].BaseType); ConstructorInfo baseConstructor; if (baset == null) { baseConstructor = hasConstructors[t].BaseType.GetConstructor(new Type[] { }); } else { baseConstructor = baset.GetConstructor(new Type[] { }); baseConstructor = (ConstructorInfo)((UserConstructor)baseConstructor).Entry.ReflectionObject; } ConstructorBuilder cb = DefineConstructor(t, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, new ParameterInfo[] {}); ILGenerator ig = cb.GetILGenerator(); ig.Emit(OpCodes.Call, baseConstructor); ig.Emit(OpCodes.Ret); uc.Entry.ReflectionObject = cb; } } }
/// <summary> /// Finally walk all members of the classes and interfaces. Methods etc. are defined here /// </summary> public void WalkClassMembers() { CheckerException exc = new CheckerException(); bool hasMain = false; for (int i = 0; i < reorderedTypes.Count; i++) { TreeNode n = reorderedTypes[i]; currentType = (UserType)n.Entry.ReflectionObject; searchPath = (List <string>)((TreeNode)n.Parent.Parent).Entry.ReflectionObject; this.searchPath.Add(currentType.Namespace); foreach (TreeNode n2 in n.Children) { try { if (n2.Type == VnvdTreeWalker.FIELD) { n2.EntryType = EntryType.Variable; IdEntry entry = new IdEntry(); entry.Node = n2; string ret = n2.GetChild(1).Type == VnvdTreeWalker.FQUALIFIER ? AbstractHelper.GetFullQualifier(n2.GetChild(1)).ToString() : n2.GetChild(1).Text; UserField field = DefineField(currentType, n2.GetChild(2).Text, AbstractHelper.GetModifiers(n2.GetChild(0)), ret); field.Entry = entry; entry.ReflectionObject = field; n2.Entry = entry; } else if (n2.Type == VnvdTreeWalker.CONSTRUCTOR) { n2.EntryType = EntryType.Constructor; IdEntry entry = new IdEntry(); entry.Node = n2; String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(2)); String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(2)); UserConstructor cons = DefineConstructor(currentType, AbstractHelper.GetModifiers(n2.GetChild(0)), parTypes, parNames); cons.Entry = entry; entry.ReflectionObject = cons; n2.Entry = entry; } else if (n2.Type == VnvdTreeWalker.METHOD) { n2.EntryType = EntryType.Method; IdEntry entry = new IdEntry(); entry.Node = n2; String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(3)); String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(3)); string ret = n2.GetChild(1).Type == VnvdTreeWalker.FQUALIFIER ? AbstractHelper.GetFullQualifier(n2.GetChild(1)).ToString() : n2.GetChild(1).Text; UserMethod met = DefineMethod(currentType, n2.GetChild(2).Text, AbstractHelper.GetModifiers(n2.GetChild(0)), ret, parTypes, parNames); if (met.Name.Equals(GeneratorManual.MAINMETHOD)) { if (hasMain) { throw new CheckerException(n2, "Duplicate main method."); } hasMain = true; } met.Entry = entry; entry.ReflectionObject = met; n2.Entry = entry; } else if (n2.Type == VnvdTreeWalker.IMETHOD) { n2.EntryType = EntryType.Method; IdEntry entry = new IdEntry(); entry.Node = n2; String[] parNames = AbstractHelper.GetParameterNames(n2.GetChild(2)); String[] parTypes = AbstractHelper.GetParameterTypes(n2.GetChild(2)); string ret = n2.GetChild(0).Type == VnvdTreeWalker.FQUALIFIER ? AbstractHelper.GetFullQualifier(n2.GetChild(0)).ToString() : n2.GetChild(0).Text; UserMethod met = DefineInterfaceMethod(currentType, n2.GetChild(1).Text, ret, parTypes, parNames); met.Entry = entry; entry.ReflectionObject = met; n2.Entry = entry; } else if (n2.Type == VnvdTreeWalker.SCONSTRUCTOR) { n2.EntryType = EntryType.Constructor; IdEntry entry = new IdEntry(); entry.Node = n2; UserConstructor cons = currentType.DefineTypeInitializer(); cons.Entry = entry; entry.ReflectionObject = cons; n2.Entry = entry; } else if (n2.Type == VnvdTreeWalker.ENUMOPTION) { n2.EntryType = EntryType.Variable; IdEntry entry = new IdEntry(); entry.Node = n2; UserField option = ((UserEnum)currentType).DefineOption(n2.GetChild(0).Text); option.Entry = entry; entry.ReflectionObject = option; n2.Entry = entry; } } catch (CheckerException ex) { exc.AddError(n2, ex.GetLastError().Second); } catch (InvalidOperationException ex) { exc.AddError(n2, ex.Message); } catch (SymbolTableException ex) { exc.AddError(n2, ex.Message); } } if (currentType.IsClass && currentType.GetConstructors().Length == 0) { UserConstructor uc = DefineConstructor(currentType, new List <string>() { "public" }, new string[] {}, new string[] {}); uc.Entry = new IdEntry(); uc.Entry.ReflectionObject = uc; } try { if (!currentType.IsInterface) { currentType.CheckInterfaces(); } } catch (CheckerException ex) { exc.AddError(n, ex.GetLastError().Second); } this.searchPath.Remove(currentType.Namespace); } if (exc.ErrorCount > 0) { throw exc; } }