public void Client_checkPasswordTest()
        {
            Client tempUser = new Client("testUser", "5555");
            Client.hashPassword(tempUser);

            Assert.IsTrue(Client.checkPassword(tempUser, "5555"));
        }
        public void Client_writeToFileTest()
        {
            Client testUser = new Client("testUser","5555");

            testUser.writeToFile();

            #region ReadClientObjectFromFile

                string pathToDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string USER_LOCATION = "\\users\\";
                string XML_EXT = ".xml";
                string writePath = pathToDir + USER_LOCATION + testUser.Name + XML_EXT;

            Client tempObj;

            //Reads from the xml file for the client.
            using (FileStream reader = new FileStream(writePath, FileMode.Open, FileAccess.Read))
            {
                DataContractSerializer ser = new DataContractSerializer(typeof(Client));
                tempObj = (Client)ser.ReadObject(reader);
            }

            Assert.AreEqual(testUser.Name, tempObj.Name);
            Assert.AreEqual(testUser.Online, tempObj.Online);
            Assert.AreEqual(testUser.Password, tempObj.Password);

            #endregion
        }
 public void Client_ConstructorTwoTest()
 {
     Client testUser = new Client("testUser");
     Assert.IsNull(testUser.Password);
     Assert.IsNull(testUser.Name);
     Assert.IsNotNull(testUser.Online);
     Assert.IsNotNull(testUser.lastRequest);
     Assert.IsNull(testUser.Salt);
 }
Beispiel #4
0
        public void A_client_must_have_an_identity_number_contact_number_and_name()
        {
            var idNumber = new IdentityNumber("7808035176089");
            var telephoneNumber = new TelephoneNumber("0125552222");
            var clientName = new PersonName("Adrian", "Freemantle");

            var client = new Client(idNumber, clientName, telephoneNumber);

            client.Identity.Id.ShouldBe(idNumber.Number);
            client.PrimaryContactNumber.ShouldBe(telephoneNumber);
            client.ClientName.ShouldBe(clientName);
        }
Beispiel #5
0
        public void GivenAGreaterThanOrEqualExpressionWithMemberOnLeftAndIntegerOnRight_ShouldReturnARangeFilterWithMemberAsFieldAndIntegerAsFromValueAndIncludeLowerTrue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Id >= 42);

            filter.Should().BeOfType<RangeFilter<int>>();
            var rangeFilter = (RangeFilter<int>)filter;
            rangeFilter.From.Equals(42).Should().BeTrue();
            rangeFilter.Field.Should().Be(client.GetFieldName<TestData, int>(x => x.Id));
            rangeFilter.IncludeLower.Should().BeTrue();
        }
Beispiel #6
0
        public void GivenALessThanExpressionWithMemberOnLeftAndDateTimeOnRight_ShouldReturnARangeFilterWithMemberAsFieldAndDateTimeAsToValueAndIncludeUpperFalse()
        {
            var client = new Client("", "");
            var filterValue = DateTime.Now;
            var filter = client.WhereFilter<TestData>(x => x.Date < filterValue);

            filter.Should().BeOfType<RangeFilter<DateTime>>();
            var rangeFilter = (RangeFilter<DateTime>)filter;
            rangeFilter.To.Equals(filterValue).Should().BeTrue();
            rangeFilter.Field.Should().Be(client.GetFieldName<TestData, DateTime>(x => x.Date));
            rangeFilter.IncludeUpper.Should().BeFalse();
        }
Beispiel #7
0
        public void Clients_over_60_with_three_or_more_insurance_products_qualify_for_pensioners_discount()
        {
            var idNumber = new IdentityNumber("5008035176089");
            var telephoneNumber = new TelephoneNumber("0125552222");
            var clientName = new PersonName("Adrian", "Freemantle");
            var client = new Client(idNumber, clientName, telephoneNumber);

            client.Purchased(new InsuranceProduct());
            client.Purchased(new InsuranceProduct());
            client.Purchased(new InsuranceProduct());

            client.QualifiesForPensionersDiscount().ShouldBe(true);
        }
Beispiel #8
0
        public void A_clients_with_same_identity_number_are_the_same_client()
        {
            var idNumber = new IdentityNumber("7808035176089");
            var telephoneNumber = new TelephoneNumber("0125552222");
            var clientName = new PersonName("Adrian", "Freemantle");
            var client = new Client(idNumber, clientName, telephoneNumber);

            var telephoneNumber2 = new TelephoneNumber("1111111111");
            var clientName2 = new PersonName("Sally", "Smith");
            var client2 = new Client(idNumber, clientName2, telephoneNumber2);

            client.ShouldBe(client2);
        }
Beispiel #9
0
        public void Can_restore_from_snapshot()
        {
            var idNumber = new IdentityNumber("5008035176089");
            var telephoneNumber = new TelephoneNumber("0125552222");
            var clientName = new PersonName("Adrian", "Freemantle");
            var client = new Client(idNumber, clientName, telephoneNumber);

            client.Purchased(new InsuranceProduct());
            client.Purchased(new InsuranceProduct());
            client.Purchased(new InsuranceProduct());

            var snapshot = (client as IEntity).GetSnapshot();

            var restored = EntityFactory.Build<Client>(snapshot);
        }
Beispiel #10
0
        public void GivenTwoAndAlsoedEqualityExpressionsInNegatedParenthesis_ShouldReturnANotFilterWithAnAndFilter()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => !(x.Id == 42 && x.Double == 42.42));

            filter.Should().BeOfType<NotFilter>();
            var notFilter = (NotFilter)filter;
        }
Beispiel #11
0
        public void GivenExpressionWithStartsWithInvokedOnReturnValueFromToLowerInvokedOnMember_ShouldAddAPrefixFilterWithMemberAsLowercaseFieldAndArgumentAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Name.ToLower().StartsWith("Hello"));

            filter.Should().BeOfType<PrefixFilter>();
            var termFilter = (PrefixFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Should().Be("Hello");
            termFilter.Field.Should().Be(client.GetFieldNameForLowercase<TestData, string>(x => x.Name));
        }
Beispiel #12
0
        public void GivenAnEqualityExpressionWithMemberOnLeftAndEnumOnRight_ShouldAddATermFilterWithMemberAsFieldAndEnumAsIntAsValue()
        {
            var client = new Client("", "");

            var filterValue = UriComponents.Host;
            var filter = client.WhereFilter<TestData>(x => x.Enum == filterValue);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals((int)filterValue).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, UriComponents>(x => x.Enum));
        }
Beispiel #13
0
        public void GivenTwoOrElsedEqualityExpressionsInParenthesisAndAnAndAlsoedEqualityExpression_ShouldAddAAndFilterWithTwoFiltersOutOfWhichOneIsAnOrFilter()
        {
            var client = new Client("", "");

            var dateValue = DateTime.Now;
            var filter = client.WhereFilter<TestData>(x => (x.Id == 42 || x.Name == "Hello") && x.Date == dateValue);

            filter.Should().BeOfType<AndFilter>();
            var andFilter = (AndFilter)filter;
            andFilter.Filters.Should().HaveCount(2);
            andFilter.Filters.First().Should().BeOfType<OrFilter>();
        }
Beispiel #14
0
        public void GivenAnIsExpressionWithSubTypeOfQueriedTypeOnRight_ShouldReturnATermFilterWithTypesFieldAndTypeNameAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x is TestDataSub);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Value.Equals(TypeHierarchyInterceptor.GetTypeName(typeof(TestDataSub))).Should().BeTrue();
            termFilter.Field.Should().Be(TypeHierarchyInterceptor.TypeHierarchyJsonPropertyName);
        }
Beispiel #15
0
        public void GivenAnIsExpressionWithMemberOnLeftAndSubTypeOfMemberTypeOnRight_ShouldReturnATermFilterWithMembersTypesFieldAndTypeNameAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Another is TestDataSub);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Value.Equals(TypeHierarchyInterceptor.GetTypeName(typeof(TestDataSub))).Should().BeTrue();
            var expectedFieldName = client.GetFieldName<TestData, TestData>(x => x.Another) + "." + TypeHierarchyInterceptor.TypeHierarchyJsonPropertyName;
            termFilter.Field.Should().Be(expectedFieldName);
        }
Beispiel #16
0
        public void GivenAnInequalityExpressionWithNullableDateTimeMemberOnLeftAndNullOnRight_ShouldAddAnExistsFilterWithMemberAsField()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.NullableDate != null);

            filter.Should().BeOfType<ExistsFilter>();
            var existsFilter = (ExistsFilter)filter;
            existsFilter.Field.Should().Be(client.GetFieldName<TestData, DateTime?>(x => x.NullableDate));
        }
Beispiel #17
0
        public void GivenAnInequalityExpressionWithMemberOnRightAndIntegerOnLeft_ShouldReturnANotFilterWithATermFilterWithMembersFieldNameAndIntegerValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Id != 42);

            filter.Should().BeOfType<NotFilter>();
            var notFilter = (NotFilter)filter;
            var termFilter = (TermFilter)notFilter.Filter;
            termFilter.Value.Equals(42).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, int>(x => x.Id));
        }
Beispiel #18
0
        public void GivenAnExpressionWithNegatedBooleanMember_ShouldAddANotFilterWithATermFilterWithMemberAsFieldAndTrueAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => !x.Bool);

            filter.Should().BeOfType<NotFilter>();
            var notFilter = (NotFilter) filter;
            notFilter.Filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)notFilter.Filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals(true).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, bool>(x => x.Bool));
        }
Beispiel #19
0
        public void GivenAnEqualityExpressionWithMemberOnLeftAndStringOnRight_ShouldAddATermFilterWithMemberAsFieldAndStringAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Name == "Hello");

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter) filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals("Hello").Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, string>(x => x.Name));
        }
Beispiel #20
0
        public void GivenAnEqualityExpressionWithMemberOnLeftAndNullableDateTimeOnRight_ShouldAddATermFilterWithMemberAsFieldAndNullableDateTimeAsValue()
        {
            var client = new Client("", "");

            var filterValue = DateTime.Now;
            var filter = client.WhereFilter<TestData>(x => x.NullableDate == filterValue);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals(filterValue).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, DateTime?>(x => x.NullableDate));
        }
Beispiel #21
0
        public void GivenTwoAndedEqualityExpressions_ShouldAddAAndFilterWithTwoFilters()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Id == 42 & x.Name == "Hello");

            filter.Should().BeOfType<AndFilter>();
            var andFilter = (AndFilter)filter;
            andFilter.Filters.Should().HaveCount(2);
        }
Beispiel #22
0
        public void GivenATypeComparisonExpressionWithGetTypeInvokedOnMemberOnLeftAndTypeOfQueriedTypeOnRight_ShouldReturnATermFilterWithMembersFieldPlusTypeFieldAndTypeNameAsValue()
        {
            var client = new Client("", "");
            var typeToMatch = typeof(TestDataSub);
            var filter = client.WhereFilter<TestData>(x => x.Another.GetType() == typeToMatch);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            var memberFieldName = client.GetFieldName<TestData, TestData>(x => x.Another);
            termFilter.Value.ShouldEqual(typeToMatch + ", " + typeToMatch.Assembly.GetName().Name);
            termFilter.Field.Should().Be(memberFieldName + "." + "$type");
        }
Beispiel #23
0
        public void GivenTwoOrElsedEqualityExpressions_ShouldAddAOrFilterWithTwoFilters()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>((x => x.Id == 42 || x.Name == "Hello"));

            filter.Should().BeOfType<OrFilter>();
            var orFilter = (OrFilter) filter;
            orFilter.Filters.Should().HaveCount(2);
        }
Beispiel #24
0
        public void GivenATypeComparisonExpressionWithTypeOfQueriedTypeOnRight_ShouldReturnATermFilterWithTypeFieldAndTypeNameAsValue()
        {
            var client = new Client("", "");
            var typeToMatch = typeof (TestDataSub);
            var filter = client.WhereFilter<TestData>(x => x.GetType() == typeToMatch);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Value.Equals(typeToMatch + ", " + typeToMatch.Assembly.GetName().Name).Should().BeTrue();
            termFilter.Field.Should().Be("$type");
        }
Beispiel #25
0
        public void GivenALessThanExpressionWithMemberOnLeftAndIntegerOnRight_ShouldReturnARangeFilterWithMemberAsFieldAndIntegerAsToValueAndIncludeUpperFalse()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Id < 42);

            filter.Should().BeOfType<RangeFilter<int>>();
            var rangeFilter = (RangeFilter<int>)filter;
            rangeFilter.To.Equals(42).Should().BeTrue();
            rangeFilter.Field.Should().Be(client.GetFieldName<TestData, int>(x => x.Id));
            rangeFilter.IncludeUpper.Should().BeFalse();
        }
Beispiel #26
0
        public void GivenExpressionWithStartsWithInvokedOnMemberWithStringComparisonInvariantCultureIgnoreCase_ShouldAddAPrefixFilterWithMemberAsLowercaseFieldAndArgumentLowercasedAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Name.StartsWith("Hello", StringComparison.InvariantCultureIgnoreCase));

            filter.Should().BeOfType<PrefixFilter>();
            var termFilter = (PrefixFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Should().Be("hello");
            termFilter.Field.Should().Be(client.GetFieldNameForLowercase<TestData, string>(x => x.Name));
        }
Beispiel #27
0
        public void GivenAnEqualityExpressionWithBooleanMemberOnLeftAndFalseOnRight_ShouldAddATermFilterWithMemberAsFieldAndFalseAsValue()
        {
            var client = new Client("", "");

            var filterValue = false;
            var filter = client.WhereFilter<TestData>(x => x.Bool == filterValue);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals(filterValue).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, bool>(x => x.Bool));
        }
Beispiel #28
0
        public void GivenExpressionWithStartsWithInvokedOnMemberWithStringComparisonOrdinal_ShouldAddAPrefixFilterWithMemberAsFieldAndArgumentAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Name.StartsWith("Hello", StringComparison.Ordinal));

            filter.Should().BeOfType<PrefixFilter>();
            var termFilter = (PrefixFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Should().Be("Hello");
            termFilter.Field.Should().Be(client.GetFieldName<TestData, string>(x => x.Name));
        }
Beispiel #29
0
        public void GivenEqualityExpressionWithToLowerWithCultureInfoInvokedOnMemberOnLeftAndStringOnRight_ShouldAddATermFilterWithMemberAsLowercaseFieldAndArgumentAsValue()
        {
            var client = new Client("", "");

            var filter = client.WhereFilter<TestData>(x => x.Name.ToLower(CultureInfo.InvariantCulture) == "Hello");

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.ShouldEqual("Hello");
            termFilter.Field.Should().Be(client.GetFieldNameForLowercase<TestData, string>(x => x.Name));
        }
Beispiel #30
0
        public void GivenAnEqualityExpressionWithIntegerPropertyFromNonQueriedClassOnLeftAndMemberOnRight_ShouldAddATermFilterWithMemberAsFieldAndIntegerAsValue()
        {
            var client = new Client("", "");
            var filter = client.WhereFilter<TestData>(x => IntProperty == x.Id);

            filter.Should().BeOfType<TermFilter>();
            var termFilter = (TermFilter)filter;
            termFilter.Should().NotBeNull();
            termFilter.Value.Equals(42).Should().BeTrue();
            termFilter.Field.Should().Be(client.GetFieldName<TestData, int>(x => x.Id));
        }