public void HasDifferentValueAsFailsWithCorrectMessage() { var mySelf = new Person() { Name = "dupdob" }; var myClone = new PersonEx() { Name = "dupdob" }; Check.ThatCode(() => { Check.That((object)null).HasDifferentValueThan((object)null); }).IsAFailingCheckWithMessage("", "The checked object is equal to the given one whereas it must not.", "The expected object: different from (using operator!=)", "\t[null] of type: [object]"); Check.ThatCode(() => { Check.That(myClone).HasDifferentValueThan(mySelf); }).IsAFailingCheckWithMessage("", "The checked value is equal to the given one whereas it must not.", "The expected value: different from (using operator!=)", "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); Check.ThatCode(value: () => { Check.That(myClone).Not.HasDifferentValueThan(new Person() { Name = "test" }); }).IsAFailingCheckWithMessage("", "The checked value is different from the expected one.", "The checked value:", "\t[NFluent.Tests.ObjectRelatedTest+PersonEx] of type: [NFluent.Tests.ObjectRelatedTest+PersonEx]", "The expected value: equals to (using !operator!=)", "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); }
public static PersonEx CreatePersonEx() { PersonEx p = CreatePersonCore <PersonEx>(); p.NickName = "CoolJoe"; return(p); }
public void FailsToUseOperator() { var mySelf = new Person() { Name = "SilNak" }; var myClone = new PersonEx() { Name = "SilNak" }; var mySon = new Son() { Name = "SilNak" }; Check.That(myClone).HasSameValueAs(mySelf); if (mySelf == myClone) { Check.That(mySelf).HasSameValueAs(myClone); } if (mySon == myClone) { Check.That(myClone).HasSameValueAs(mySon); } if (myClone == mySelf) { Check.That(myClone).HasSameValueAs(mySelf); } Check.That(myClone).HasSameValueAs(myClone); Check.That(mySelf).HasDifferentValueThan(4); }
public void CompareCoercesToStringOnDemandFromConfiguration() { //Arrange. PersonEx p1 = ModelsHelper.CreatePersonEx(); PersonExWithPropMap p2 = ModelsHelper.CreatePersonExWithPropMapping(); var config = ComparerConfigurator.Configure <PersonEx, PersonExWithPropMap>(true) .MapProperty(src => src.Gender, dst => dst.Gender, true); ObjectComparer comparer = config.CreateComparer(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult pcr = result[nameof(Person.Gender)]; pcr.Should().NotBeNull(); (pcr.Result & ComparisonResult.StringCoercion).Should().Be(ComparisonResult.StringCoercion); pcr.MapUsed.Should().NotBeNull(); pcr.MapUsed.ForceStringValue.Should().BeTrue(); pcr.Value1.Should().NotBeNull(); pcr.Value1.Should().BeOfType <string>(); pcr.Value2.Should().NotBeNull(); pcr.Value2.Should().BeOfType <string>(); }
public void HasSameValueAsFailsWithCorrectMessage() { var mySelf = new Person() { Name = "dupdob" }; var myClone = new PersonEx() { Name = "tpierrain" }; Check.ThatCode(() => { Check.That(myClone).HasSameValueAs(mySelf); }) .ThrowsAny() .WithMessage( Environment.NewLine + "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+PersonEx] of type: [NFluent.Tests.ObjectRelatedTest+PersonEx]" + Environment.NewLine + "The expected value: equals to (using operator==)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); Check.ThatCode(() => { Check.That(myClone).Not.HasSameValueAs(new Person() { Name = "tpierrain" }); }) .IsAFailingCheckWithMessage("", "The checked value is equal to the given one whereas it must not.", "The expected value: different from (using !operator==)", "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); }
public void PropertyNotFound() { //Arrange. PersonEx p1 = ModelsHelper.CreatePersonEx(); Person p2 = ModelsHelper.CreatePerson(); ObjectComparer comparer = ObjectComparer.Create <PersonEx, Person>(); //Act. var result = comparer.Compare(p1, p2, out bool isDifferent); //Assert. isDifferent.Should().BeFalse(); result[nameof(PersonEx.NickName)].Result.Should().Be(ComparisonResult.PropertyNotFound); }
public void ConfigurationIncludesAttributedPropertyMappings() { //Arrange. PersonExWithPropMap p1 = ModelsHelper.CreatePersonExWithPropMapping(); PersonEx p2 = ModelsHelper.CreatePersonEx(); var config = ComparerConfigurator.Configure <PersonExWithPropMap, PersonEx>(); ObjectComparer comparer = config.CreateComparer(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result[nameof(PersonExWithPropMap.NewNickName)].MapUsed.Should().NotBeNull(); }
public void IgnoreForComparisonAttributeIgnoreForOthers(Type p1Type, Person p1) { //Arrange. PersonEx p2 = ModelsHelper.CreatePersonEx(); ObjectComparer comparer = new ObjectComparer(p1Type, typeof(PersonEx)); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult proprtyResult = result[nameof(PersonExWithIgnore.NickName)]; proprtyResult.Should().NotBeNull(); proprtyResult.Result.Should().Be(ComparisonResult.PropertyIgnored); }
public void HasDifferentValueAsFailsWithCorrectMessage() { var mySelf = new Person() { Name = "dupdob" }; var myClone = new PersonEx() { Name = "dupdob" }; Check.ThatCode(() => { Check.That(myClone).HasDifferentValueThan(mySelf); }) .ThrowsAny() .WithMessage( Environment.NewLine + "The checked value is equal to the expected one whereas it must not." + Environment.NewLine + "The expected value: different from (using operator!=)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); }
public void PersonDetails() { string auraId = Helpers.GetAuraId(Convert.ToString(base.Session["AptifyUniqueId"])); if (string.IsNullOrEmpty(auraId)) { base.Response.Redirect("/Login?ReturnUrl=" + HttpUtility.UrlEncode(base.Request.Url.AbsoluteUri)); } PersonEx personById = Helpers.GetPersonById(Convert.ToInt32(base.Session["PersonID"]), auraId); this.txtName1.Text = Helpers.TrimOrNull(personById.FirstName) + " " + Helpers.TrimOrNull(personById.LastName); this.Attendee.Text = this.txtName1.Text; this.txtTitle.Text = Helpers.TrimOrNull(personById.Title); this.txtEmail.Text = Helpers.TrimOrNull(personById.Email); if (personById.Company != null) { this.txtCompany.Text = Helpers.TrimOrNull(personById.Company.Name); } if (personById.PreferredAddress.Contains("Home") && personById.HomeAddress != null) { this.txtHomeAddressLine1.Text = Helpers.TrimOrNull(personById.HomeAddress.Line1); this.txtHomeAddressLine2.Text = Helpers.TrimOrNull(personById.HomeAddress.Line2); this.txtHomeCity.Text = Helpers.TrimOrNull(personById.HomeAddress.City); this.txtHomeZip.Text = Helpers.TrimOrNull(personById.HomeAddress.PostalCode); this.SetComboValue(ref this.ddlPersonalInformationCountry, personById.HomeAddress.Country); this.SetComboValue(ref this.ddbPersonalInformationState, personById.HomeAddress.StateProvince); } else { if (personById.BusinessAddress != null) { this.txtHomeAddressLine1.Text = Helpers.TrimOrNull(personById.BusinessAddress.Line1); this.txtHomeAddressLine2.Text = Helpers.TrimOrNull(personById.BusinessAddress.Line2); this.txtHomeCity.Text = Helpers.TrimOrNull(personById.BusinessAddress.City); this.txtHomeZip.Text = Helpers.TrimOrNull(personById.BusinessAddress.PostalCode); this.SetComboValue(ref this.ddlPersonalInformationCountry, personById.BusinessAddress.Country); this.SetComboValue(ref this.ddbPersonalInformationState, personById.BusinessAddress.StateProvince); } } this.PopulateStateByCountryId(); this.txtAreaHomePhone.Text = Helpers.TrimOrNull(personById.PhoneAreaCode); this.txtHomePhone.Text = Helpers.TrimOrNull(personById.Phone); this.txtPhoneExt.Text = Helpers.TrimOrNull(personById.PhoneExtension); }
public void CompareUsesMappingsFromConfiguration() { //Arrange. PersonEx p1 = ModelsHelper.CreatePersonEx(); PersonExWithPropMap p2 = ModelsHelper.CreatePersonExWithPropMapping(); var config = ComparerConfigurator.Configure <PersonEx, PersonExWithPropMap>(true) .MapProperty(src => src.NickName, dst => dst.NewNickName); ObjectComparer comparer = config.CreateComparer(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyMap map = result[nameof(PersonEx.NickName)].MapUsed; map.Should().NotBeNull(); map.TargetType.Should().Be(typeof(PersonExWithPropMap)); map.TargetProperty.Should().Be(nameof(PersonExWithPropMap.NewNickName)); }
public void PropertyIsIgnoredForSpecificType() { //Arrange. Person p1 = ModelsHelper.CreatePerson(); PersonEx p2 = ModelsHelper.CreatePersonEx(); var config = ComparerConfigurator.Configure <Person, PersonEx>() .IgnoreProperty(src => src.Email); ObjectComparer comparer = config.CreateComparer(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); PropertyComparisonResult pcr = result[nameof(Person.Email)]; pcr.Should().NotBeNull(); pcr.Result.Should().Be(ComparisonResult.PropertyIgnored); pcr.MapUsed.Should().NotBeNull(); pcr.MapUsed.Operation.Should().Be(PropertyMapOperation.IgnoreProperty); pcr.Property1.IgnoreProperty.Should().Be(IgnorePropertyOptions.DoNotIgnore); }
public void CompareUsesComparersFromConfiguration() { //Arrange. PersonEx p1 = ModelsHelper.CreatePersonEx(); PersonExWithPropMap p2 = ModelsHelper.CreatePersonExWithPropMapping(); Mock <IComparer> customComparer = new Mock <IComparer>(); customComparer.Setup(m => m.Compare(It.IsAny <Genders>(), It.IsAny <object>())) .Returns(-1) .Verifiable($"{nameof(IComparer.Compare)}() method was not invoked."); var config = ComparerConfigurator.Configure <PersonEx, PersonExWithPropMap>(true) .MapProperty(src => src.NickName, dst => dst.NewNickName) .AddComparer <Genders>(customComparer.Object); ; ObjectComparer comparer = config.CreateComparer(); //Act. var result = comparer.Compare(p1, p2, out bool _); //Assert. result.Should().NotBeNull(); customComparer.VerifyAll(); }
public static string FormatDescriptionLine(PersonEx person, WebShoppingCartDetails line, OrderLineViewModel item) { //person id 2 is guest return(string.Format("Registration for {0} {1}.", person.FirstName, person.LastName)); }
public void HasDifferentValueAsFailsWithCorrectMessage() { var mySelf = new Person() { Name = "dupdob" }; var myClone = new PersonEx() { Name = "dupdob" }; Check.ThatCode(() => { Check.That(myClone).HasDifferentValueThan(mySelf); }) .ThrowsAny() .WithMessage( Environment.NewLine+ "The checked value is equal to the expected one whereas it must not." + Environment.NewLine + "The expected value: different from (using operator!=)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); }
public void HasSameValueAsFailsWithCorrectMessage() { var mySelf = new Person() { Name = "dupdob" }; var myClone = new PersonEx() { Name = "tpierrain" }; Check.ThatCode(() => { Check.That(myClone).HasSameValueAs(mySelf); }) .ThrowsAny() .WithMessage( Environment.NewLine+ "The checked value is different from the expected one." + Environment.NewLine + "The checked value:" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+PersonEx] of type: [NFluent.Tests.ObjectRelatedTest+PersonEx]" + Environment.NewLine + "The expected value: equals to (using operator==)" + Environment.NewLine + "\t[NFluent.Tests.ObjectRelatedTest+Person] of type: [NFluent.Tests.ObjectRelatedTest+Person]"); }
public void FailsToUseOperator() { var mySelf = new Person() { Name = "SilNak" }; var myClone = new PersonEx() { Name = "SilNak" }; var mySon = new Son() { Name = "SilNak" }; Check.That(myClone).HasSameValueAs(mySelf); if (mySelf == myClone) Check.That(mySelf).HasSameValueAs(myClone); if (mySon == myClone) Check.That(myClone).HasSameValueAs(mySon); if (myClone == mySelf) Check.That(myClone).HasSameValueAs(mySelf); Check.That(myClone).HasSameValueAs(myClone); Check.That(mySelf).HasDifferentValueThan(4); }
protected override void OnFixtureSetUp() { _person = new PersonEx(new OneNameFullName("schmuck")); // can be a Salesman _person.AddRole(new Salesman()); }
private bool SavePersonalInfo() { string auraId = Helpers.GetAuraId(Convert.ToString(base.Session["AptifyUniqueId"])); if (string.IsNullOrEmpty(auraId)) { base.Response.Redirect("/Login?ReturnUrl=" + HttpUtility.UrlEncode(base.Request.Url.AbsoluteUri)); } this.lblStatus.Visible = false; string text = ""; string baseUrl = ConfigurationManager.AppSettings["ServicesUrl"] + "/icpas/api/ProfileUpdatePersonInfoSave/SaveProfilePersonalInfoMeetingReg"; string value4; string value3; string value2; string value = value2 = (value3 = (value4 = "")); RestClient restClient = new RestClient(baseUrl); RestRequest restRequest = new RestRequest(Method.POST); restRequest.AddHeader("x-aura-token", auraId); restRequest.AddParameter("PersonID", base.Session["PersonID"]); if (!string.IsNullOrEmpty(this.txtHomeAddressLine1.Text) | !string.IsNullOrEmpty(this.txtHomeAddressLine2.Text)) { value2 = this.txtHomeAddressLine1.Text; value = this.txtHomeAddressLine2.Text; } string text2 = this.txtHomeCity.Text; string value5 = (!string.IsNullOrEmpty(this.ddbPersonalInformationState.SelectedValue)) ? this.ddbPersonalInformationState.SelectedItem.Text : ""; int num = (!string.IsNullOrEmpty(this.ddlPersonalInformationCountry.SelectedValue)) ? Convert.ToInt32(this.ddlPersonalInformationCountry.SelectedValue) : -1; string value6 = (!string.IsNullOrEmpty(this.ddlPersonalInformationCountry.SelectedValue)) ? this.ddlPersonalInformationCountry.SelectedItem.Text : ""; string value7 = this.txtHomeZip.Text.Trim(); string value8 = this.txtEmail.Text.Trim(); string value9 = this.txtPhoneExt.Text.Trim(); if (!string.IsNullOrEmpty(this.txtAreaHomePhone.Text) && !string.IsNullOrEmpty(this.txtHomePhone.Text)) { if (this.txtAreaHomePhone.Text.Length <= 5 & this.txtHomePhone.Text.Length <= 15) { value3 = this.txtAreaHomePhone.Text; value4 = this.txtHomePhone.Text; } else { text += "Please enter valid Home phone number. \n"; } } if (text.Length > 1) { this.lblStatus.Text = text; this.lblStatus.Visible = true; return(false); } PersonEx personById = Helpers.GetPersonById(Convert.ToInt32(base.Session["PersonID"]), auraId); restRequest.AddParameter("PreferredAddress", personById.PreferredAddress); restRequest.AddParameter("Email1", value8); restRequest.AddParameter("AddressLine1", value2); restRequest.AddParameter("AddressLine2", value); restRequest.AddParameter("City", text2); restRequest.AddParameter("State", value5); restRequest.AddParameter("Country", value6); restRequest.AddParameter("CountryCodeID", num); restRequest.AddParameter("ZipCode", value7); restRequest.AddParameter("AreaCode", value3); restRequest.AddParameter("Phone", value4); restRequest.AddParameter("PhoneExtension", value9); IRestResponse restResponse = restClient.Execute(restRequest); string arg_35F_0 = restResponse.Content; return(true); }
/// <summary> /// 元组,一种方便快捷的数据类型,无需声明结构,即可立即使用。 /// 元组中的属性都是可以修改值的,并不是只读,这点和其他某类编程语言不大一样。 /// </summary> public void TupleOne() { Random rnd = new Random(); //第一种场景:直接赋值 var results = (1, 2, 3, "Name", "Time"); // 等价于 var ( Item1, Item2, Item3, Item4, Item5) Console.WriteLine(results); Console.WriteLine(results.Item1 + "," + results.Item2 + "," + results.Item3); //第二种场景:函数返回元组 results = GetTupleDataOne(rnd); results.Item2 = 3; Console.WriteLine(results); //第三种场景:逐个字段命名 (int i1, int i2, int i3, string name, string time) = GetTupleDataOne(rnd); Console.WriteLine($"{i1} {i2} {i3} {name} {time}"); i1 = i2 = i3 = 10; //第四种场景:已有变量 string Name, Time; (i1, i2, i3, Name, Time) = GetTupleDataOne(rnd); Console.WriteLine($"{i1} {i2} {i3} {name} {Time}"); //第五种场景:遇到弃元,虽然元组返回多个数据,但是我只想要其中某两个的时候,可以使用这种。 (_, _, _, Name, Time) = GetTupleDataOne(rnd); Console.WriteLine($"{i1} {i2} {i3} {name} {Time}"); //第六种场景:对于类对象,也可以方便的获取其成员变成元组数据,这里使用Deconstruct方法。这样后续使用该功能的时候,就不用主动明显的调用方法。 var p = new PersonEx("A1", "B1", "C1", "D1", "G1"); // 调用Deconstruct方法,快速获取p的数据,并赋值到元组上。 var(fName, lName, city, state) = p; var(fName1, lName1) = p; Console.WriteLine($" {fName} {lName} {city} {state}"); //第七种场景:可以声明Deconstruct为静态类的静态函数,第一个参数为需要处理的对象类型。以下功能依赖于ReflectionExtensions的Deconstruct方法。 Type dateType = typeof(DateTime); PropertyInfo prop = dateType.GetProperty("Now"); var(isStatic, isRO, isIndexed, propType) = prop; Console.WriteLine($"\nThe {dateType.FullName}.{prop.Name} property:"); Console.WriteLine($" PropertyType: {propType.Name}"); Console.WriteLine($" Static: {isStatic}"); Console.WriteLine($" Read-only: {isRO}"); Console.WriteLine($" Indexed: {isIndexed}"); Type listType = typeof(List <>); prop = listType.GetProperty("Item", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); var(hasGetAndSet, sameAccess, accessibility, getAccessibility, setAccessibility) = prop; Console.Write($"\nAccessibility of the {listType.FullName}.{prop.Name} property: "); if (!hasGetAndSet | sameAccess) { Console.WriteLine(accessibility); } else { Console.WriteLine($"\n The get accessor: {getAccessibility}"); Console.WriteLine($" The set accessor: {setAccessibility}"); } }