public void Should_Return_Scalar_Value()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable<TestPerson>();

                var row = new TestPerson
                {
                    Id = Guid.NewGuid(),
                    Long = 1,
                    Decimal = 1.1M,
                    Double = 1.1,
                    Float = 1.1f,
                };
                db.Insert(row);

                var q = db.From<TestPerson>().Where(x => x.Id == row.Id);

                Assert.That(db.Scalar<Guid>(q.Select(x => x.Id)), Is.EqualTo(row.Id));
                Assert.That(db.Scalar<long>(q.Select(x => x.Long)), Is.EqualTo(row.Long));
                Assert.That(db.Scalar<decimal>(q.Select(x => x.Decimal)), Is.EqualTo(row.Decimal));
                Assert.That(db.Scalar<double>(q.Select(x => x.Double)), Is.EqualTo(row.Double).Within(.1d));
                Assert.That(db.Scalar<float>(q.Select(x => x.Float)), Is.EqualTo(row.Float));
            }
        }
        public void Match_IgnoreScalarFieldPathNotExist_ThrowsSnapshotFieldException()
        {
            // arrange
            string snapshotName =
                nameof(SnapshotTests) + "." +
                nameof(Match_IgnoreScalarFieldPathNotExist_ThrowsSnapshotFieldException);

            TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton()
                                    .Build();

            // act & assert
            Assert.Throws <SnapshotFieldException>(() => Snapshot.Match(testPerson,
                                                                        snapshotName, matchOptions => matchOptions.IgnoreField <decimal>("alt")));
        }
        public void Match_IgnoreScalarFieldNullConvertError_ThrowsSnapshotFieldException()
        {
            // arrange
            string snapshotName =
                nameof(SnapshotTests) + "." +
                nameof(Match_IgnoreScalarFieldNullConvertError_ThrowsSnapshotFieldException);

            TestPerson testPerson = TestDataBuilder.TestPersonSandraSchneider()
                                    .Build();

            // act & assert
            Assert.Throws <SnapshotFieldException>(() => Snapshot.Match(
                                                       testPerson, snapshotName, matchOptions => matchOptions.IgnoreField <int>("Age")));
        }
Exemple #4
0
        public void SourceManipulation()
        {
            var people = TestPerson.CreatePeopleDictionary();

            using var query = people.ToActiveEnumerable();
            void checkSum(int against) => Assert.AreEqual(against, query.Sum(person => person !.Name !.Length));

            Assert.AreEqual(0, query.GetElementFaults().Count);
            checkSum(74);
            people.Add(people.Count, people[0]);
            checkSum(78);
            people[0].Name = "Johnny";
            checkSum(82);
        }
Exemple #5
0
        public void ObjectWithOneInvalidEntryCollectionIsNotValid()
        {
            var dav     = new DataAnnotationsValidator(new DottedNumberCollectionPropertyNamingStrategy());
            var request = new TestPerson {
                Name = "Test Person", PhoneNumbers = new TestPhone[] { new TestPhone {
                                                                           Category = "home", Number = ""
                                                                       } }
            };
            List <ValidationResult> results = new List <ValidationResult>();
            var isValid = dav.TryValidateObjectRecursive(request, results, new ValidationContext(request));

            Assert.IsFalse(isValid);
            Assert.AreEqual(1, results.Count);
        }
Exemple #6
0
        public void UITest()
        {
            TestPerson model = new TestPerson() 
            {
                FirstName = "Guilherme"
            };

            HtmlPresenter<TestPerson> presenter = HtmlPresenter<TestPerson>.GetInstance(1033);
            StringBuilder sb = new StringBuilder();

            presenter.Render(new StringWriter(sb), model, true);

            Trace.WriteLine(sb);
        }
Exemple #7
0
        public void SourceManipulation()
        {
            var people = new ObservableDictionary <string, TestPerson>(TestPerson.CreatePeopleCollection().ToDictionary(p => p.Name !));

            using var aggregate = people.ActiveMax((key, value) => value.Name !.Length);
            Assert.IsNull(aggregate.OperationFault);
            Assert.AreEqual(7, aggregate.Value);
            people.Add("John2", people["John"]);
            Assert.AreEqual(7, aggregate.Value);
            people["John"].Name = "Johnathon";
            Assert.AreEqual(9, aggregate.Value);
            people["John"].Name = "John";
            Assert.AreEqual(7, aggregate.Value);
        }
Exemple #8
0
        public void SourceManipulationUnindexed()
        {
            var argumentOutOfRangeThrown = false;
            var people = TestPerson.CreatePeopleCollection();

            try
            {
                using var groupsExpr = people.ActiveGroupBy(person => person.Name !.Length, IndexingStrategy.NoneOrInherit);
            }
            catch (ArgumentOutOfRangeException)
            {
                argumentOutOfRangeThrown = true;
            }
            Assert.IsTrue(argumentOutOfRangeThrown);
        }
Exemple #9
0
        public void Match_AssertScalarStringFieldToInteger_SuccessfulMatch()
        {
            // arrange
            string snapshotName = nameof(SnapshotTests) + "." +
                                  nameof(Match_AssertScalarStringFieldToInteger_SuccessfulMatch);

            TestPerson testChild = TestDataBuilder.TestPersonMarkWalton()
                                   .WithFirstname(22.ToString())
                                   .Build();

            // act & assert
            Snapshot.Match(testChild, snapshotName,
                           matchOption => matchOption.Assert(fieldOption =>
                                                             Assert.Equal(22, fieldOption.Field <int>("Firstname"))));
        }
Exemple #10
0
        public void Match_AssertScalarStringFieldUnequal_ThrowsSnapshotCompareException()
        {
            // arrange
            string snapshotName =
                nameof(SnapshotTests) + "." +
                nameof(Match_AssertScalarStringFieldUnequal_ThrowsSnapshotCompareException);

            TestPerson testChild = TestDataBuilder.TestPersonMarkWalton()
                                   .Build();

            // act & assert
            Assert.Throws <SnapshotCompareException>(() => Snapshot.Match(
                                                         testChild, snapshotName, matchOption => matchOption.Assert(fieldOption =>
                                                                                                                    Assert.Equal("Anna", fieldOption.Field <string>("Children[2].Name")))));
        }
Exemple #11
0
        public void Match_AssertScalarGuidNullField_SuccessfulMatch()
        {
            // arrange
            string snapshotName = nameof(SnapshotTests) + "." +
                                  nameof(Match_AssertScalarGuidNullField_SuccessfulMatch);

            TestPerson testPerson = TestDataBuilder.TestPersonSandraSchneider()
                                    .WithId(null)
                                    .Build();

            // act & assert
            Snapshot.Match(testPerson, snapshotName,
                           matchOption => matchOption.Assert(
                               fieldOption => Assert.Null(fieldOption.Field <Guid?>("Id"))));
        }
Exemple #12
0
        public void Match_AssertScalarGuidFieldNotMatch_ThrowsSnapshotCompareException()
        {
            // arrange
            string snapshotName = nameof(SnapshotTests) + "." +
                                  nameof(Match_AssertScalarGuidFieldNotMatch_ThrowsSnapshotCompareException);

            TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton().Build();

            // act & assert
            Assert.Throws <SnapshotCompareException>(
                () => Snapshot.Match(testPerson, snapshotName,
                                     matchOption => matchOption.Assert(
                                         fieldOption => Assert.Equal(fieldOption.Field <Guid>("Id"),
                                                                     Guid.Parse("fcf04ca6-d8f2-4214-a3ff-d0ded5bad4de")))));
        }
Exemple #13
0
        public void Match_IgnoreComplexObjectField_SuccessfulIgnored()
        {
            // arrange
            string snapshotName = nameof(SnapshotTests) + "." +
                                  nameof(Match_IgnoreComplexObjectField_SuccessfulIgnored);

            TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton()
                                    .Build();

            testPerson.Address = null;

            // act & assert
            Snapshot.Match(testPerson, snapshotName,
                           matchOptions => matchOptions.IgnoreField <object>("Address"));
        }
Exemple #14
0
        public void Match_TheoryMatchSingleSnapshot_OneFieldNotEqual(int age, decimal size)
        {
            // arrange
            string snapshotName = nameof(SnapshotTests) + "." +
                                  nameof(Match_TheoryMatchSingleSnapshot_OneFieldNotEqual);

            TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton()
                                    .WithAge(age).WithSize(size).Build();

            testPerson.Address.Country.CountryCode = CountryCode.US;

            // act & assert
            Assert.Throws <SnapshotCompareException>(() => Snapshot.Match(
                                                         testPerson, snapshotName, SnapshotNameExtension.Create(age, size)));
        }
        public void CreatePerson_VerifyPersonsByIgnoringId_SuccessfulVerified(
            string firstname, string lastname)
        {
            // arrange
            var serviceClient = new ServiceClient();

            // act
            TestPerson person = serviceClient.CreatePerson(
                Guid.NewGuid(), firstname, lastname);

            // assert
            Snapshot.Match(person,
                           SnapshotNameExtension.Create(firstname, lastname),
                           matchOptions => matchOptions.IgnoreField("Id"));
        }
        public void Throw_MissingMethodException_WhenShouldThrowOnMissingIsTrueAndMethodNotFound()
        {
            // Arrange
            TestPerson           instance    = this.fixture.Create <TestPerson>();
            Mock <IFunkyFactory> factoryMock = TestHelper.GetMockedFunkyFactory();
            Indexed sut = new Indexed(instance, true, factoryMock.Object);

            // Act & Assert
            MissingMethodException ex = Assert.Throws <MissingMethodException>(() =>
            {
                object _ = sut[TestConst.InvalidPropertyName];
            });

            StringAssert.Contains(TestConst.InvalidPropertyName, ex.Message);
        }
Exemple #17
0
        public void NotThrow_WhenPropertyIsValueTypeAndNullIsPassed()
        {
            // Arrange
            TestPerson           instance    = new TestPerson();
            int                  expectedAge = this.fixture.Create <int>();
            Mock <IFunkyFactory> factoryMock = TestHelper.GetMockedFunkyFactory();

            factoryMock.Setup(x => x.GetDefaultValue(It.IsAny <Type>()))
            .Returns(expectedAge);
            Indexed sut = new Indexed(instance, false, factoryMock.Object);

            // Act & Assert
            Assert.DoesNotThrow(() => sut.Set(nameof(TestPerson.Age), (object)null));
            Assert.AreEqual(expectedAge, instance.Age);
        }
        public void ShouldHaveGeneratedDataForAllFields()
        {
            TestPerson.GenerateRandomData(false);

            Assert.That(TestPerson.Address, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.City, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.Email, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.FirstName, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.Gender, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.LastName, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.Phone, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.SocialSecurityNumber, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.Zipcode, Is.Not.Null.Or.Empty);
            Assert.That(TestPerson.BirthDate, Is.Not.Null.And.GreaterThanOrEqualTo(new DateTime(1910, 1, 1)));
        }
        public void Return_FalseAndGetNull_WhenKeyDoesNotExist()
        {
            // Arrange
            object result;
            Mock <IFunkyFactory> factory = TestHelper.GetMockedFunkyFactory();
            TestPerson           person  = this.fixture.Create <TestPerson>();
            Indexed sut = new Indexed(person, true, factory.Object);

            // Act
            bool returnValue = sut.TryGetValue(TestConst.InvalidPropertyName, out result);

            // Assert
            Assert.IsNull(result);
            Assert.IsFalse(returnValue);
        }
            public void shouldnt_have_cdata_in_the_xml()
            {
                TestPerson expected = new TestPerson();

                expected.Name = "John << Doe";
                xstream.Alias <TestPerson>("person");

                string xml = xstream.ToXml(expected);

                Console.WriteLine(xml);
                TestPerson actual = xstream.FromXml <TestPerson>(xml);

                Assert.IsFalse(xml.Contains("<![CDATA["));
                Assert.AreEqual(expected.Name, actual.Name);
            }
Exemple #21
0
        public void NestedLockedTest()
        {
            var initial = new TestPerson()
            {
                FirstName  = "John",
                LastName   = "Doe",
                IsAdult    = true,
                FirstChild = new TestPerson()
                {
                    FirstName  = "Baby",
                    LastName   = "Doe",
                    IsAdult    = false,
                    FirstChild = new TestPerson()
                    {
                        FirstName  = "Mika",
                        LastName   = "Doe",
                        IsAdult    = false,
                        FirstChild = new TestPerson()
                        {
                            FirstName = "Play",
                            LastName  = "Doe",
                            IsAdult   = false,
                        },
                    },
                },
            };

            ITestPerson person = ITestPerson.Produce(initial);

            var mutablePerson = (TestPerson)person;

            Assert.Throws <ImmutableException>(() =>
            {
                mutablePerson.FirstName = "Test";
            });
            Assert.Throws <ImmutableException>(() =>
            {
                mutablePerson.FirstChild.FirstName = "Test";
            });
            Assert.Throws <ImmutableException>(() =>
            {
                mutablePerson.FirstChild.FirstChild.FirstName = "Test";
            });
            Assert.Throws <ImmutableException>(() =>
            {
                mutablePerson.FirstChild.FirstChild.FirstChild.FirstName = "Test";
            });
        }
Exemple #22
0
        public async Task Match_TheoryAsyncMatchSingleSnapshot_SuccessfulMatch(int age, decimal size)
        {
            // arrange
            await Task.Delay(1);

            TestPerson testPerson = TestDataBuilder.TestPersonMarkWalton()
                                    .WithAge(age).WithSize(size).Build();

            await Task.Delay(1);

            // act
            Snapshot.Match <TestPerson>(testPerson, SnapshotNameExtension.Create(age, size));

            // assert
            await Task.Delay(1);
        }
Exemple #23
0
        public void Call_GetDefaultValueMethod_OnceWithCorrectParams_WhenPropertyIsValueTypeAndNullIsPassed()
        {
            // Arrange
            TestPerson           instance    = new TestPerson();
            Mock <IFunkyFactory> factoryMock = TestHelper.GetMockedFunkyFactory();
            IIndexed             sut         = new Indexed(instance, false, factoryMock.Object);

            factoryMock.Setup(x => x.GetDefaultValue(It.Is <Type>(t => t == typeof(int))))
            .Returns(0);

            // Act
            sut.Set(nameof(TestPerson.Age), (object)null);

            // Assert
            factoryMock.Verify(x => x.GetDefaultValue(It.Is <Type>(t => t == typeof(int))), Times.Once);
        }
        public void ReturnDefaultValue_WhenShouldThrowOnMissingIsTrueAndMethodNotFound_WhenGenericMethod()
        {
            // Arrange
            TestPerson           instance    = this.fixture.Create <TestPerson>();
            Mock <IFunkyFactory> factoryMock = TestHelper.GetMockedFunkyFactory();
            int     actual = -1;
            Indexed sut    = new Indexed(instance, false, factoryMock.Object);

            // Act & Assert
            Assert.DoesNotThrow(() =>
            {
                actual = sut.Get <int>(TestConst.InvalidPropertyName);
            });

            Assert.AreEqual(0, actual);
        }
        public void ReturnNull_WhenThrowOnMissingIsTrueAndMethodNotFound_WhenGenericMethod()
        {
            // Arrange
            TestPerson           instance    = this.fixture.Create <TestPerson>();
            Mock <IFunkyFactory> factoryMock = TestHelper.GetMockedFunkyFactory();
            string  actual = string.Empty;
            Indexed sut    = new Indexed(instance, false, factoryMock.Object);

            // Act & Assert
            Assert.DoesNotThrow(() =>
            {
                actual = sut.Get <string>(TestConst.InvalidPropertyName);
            });

            Assert.AreEqual(null, actual);
        }
Exemple #26
0
        public void DifferentSynchronizationContexts()
        {
            var invalidThrown = false;
            var left          = TestPerson.CreatePeopleCollection(new AsyncSynchronizationContext());
            var right         = TestPerson.CreatePeopleCollection(new AsyncSynchronizationContext());

            try
            {
                using var query = left.ActiveConcat(right);
            }
            catch (InvalidOperationException)
            {
                invalidThrown = true;
            }
            Assert.IsTrue(invalidThrown);
        }
        public void SuperHashTableGetDataTest()
        {
            var table   = new SuperHashTable <TestPerson>(10);
            var person1 = new TestPerson("Andrew", 12, 0);
            var person2 = new TestPerson("Alice", 45, 1);
            var person3 = new TestPerson("Barbara", 45, 1);
            var person4 = new TestPerson("Colin", 25, 0);

            table.Add(person1);
            table.Add(person2);
            table.Add(person3);
            table.Add(person4);

            Assert.AreEqual(2, table.GetData((int)'A').Count);
            Assert.AreEqual(25, table.GetData((int)'C')[0].Age);
        }
        public void CreatePerson_VerifyPersonByIgnoringSeveralFields_SuccessfulVerified()
        {
            // arrange
            var serviceClient = new ServiceClient();

            // act
            TestPerson person = serviceClient.CreatePerson(
                Guid.NewGuid(), "David", "Mustermann");

            // assert
            Snapshot.Match(person,
                           matchOptions => matchOptions
                           .IgnoreField("Id")
                           .IgnoreField("Address.Plz")
                           .IgnoreField("Relatives[0].Address.Country.Name"));
        }
        public void Match_IsTypeWildcardScalarFieldsOneEntry_SuccessfulMatch()
        {
            // arrange
            TestPerson testPerson = TestDataBuilder.TestPersonSandraSchneider()
                                    .AddChild(TestDataBuilder.TestChildJames().Build())
                                    .Build();

            testPerson.Children.ElementAt(0).DateOfBirth = DateTime.Parse("2015-08-17");

            // act & assert
            Snapshot.Match <TestPerson>(testPerson,
                                        matchOptions => matchOptions.IsTypeFields <DateTime>("Children[*].DateOfBirth"));
            Snapshot.Match <TestPerson>(testPerson,
                                        matchOptions => matchOptions.IsType <DateTime>(
                                            option => option.Fields <DateTime>("Children[*].DateOfBirth")));
        }
Exemple #30
0
        public void SourceManipulation()
        {
            var people = TestPerson.CreatePeopleCollection();

            using (var aggregate = people.ActiveMax(p => p.Name.Length))
            {
                Assert.IsNull(aggregate.OperationFault);
                Assert.AreEqual(7, aggregate.Value);
                people.Add(people[0]);
                Assert.AreEqual(7, aggregate.Value);
                people[0].Name = "Johnathon";
                Assert.AreEqual(9, aggregate.Value);
                people[0].Name = "John";
                Assert.AreEqual(7, aggregate.Value);
            }
        }
        public void Match_CircularReference_SuccessfulMatch()
        {
            // arrange
            TestPerson markWalton = TestDataBuilder.TestPersonMarkWalton()
                                    .Build();


            TestPerson sandraSchneider = TestDataBuilder.TestPersonSandraSchneider()
                                         .AddRelative(markWalton)
                                         .Build();

            markWalton.Relatives = new[] { sandraSchneider };

            // act & assert
            Snapshot.Match <TestPerson>(markWalton);
        }
Exemple #32
0
        public void For_Extract_When_ExpressionIsNotMemberExpression_Then_ExceptionIsThrown()
        {
            // Arrange:
            var testPerson = new TestPerson
            {
                AnyProperty = "PersonName"
            };
            Expression <Func <TestPerson, int> > expression = person => person.AnyMethod();

            // Act:
            var extractor = new PropertyExtractor <TestPerson>();
            var exception = Assert.Throws <ArgumentException>(() => extractor.Extract(expression));

            // Assert:
            exception.Message.Should().Contain("must be member expression");
        }
        public ActionResult Captura(TestPerson.Models.Person P, HttpPostedFileBase Foto)
        {
            try
            {
                TestEntities context = new TestEntities();
                Byte[] bytes = null;

                if (Foto != null)
                {
                    Stream str = Foto.InputStream;
                    BinaryReader br = new BinaryReader(str);
                    bytes = br.ReadBytes((Int32)str.Length);
                }
                if (P.Id != 0)
                {
                    var DatoOriginal = context.Personas.Find(P.Id);
                    DatoOriginal.Nombre = P.Nombre;
                    DatoOriginal.FechaNacimiento = Convert.ToDateTime(P.FechaNac);
                    DatoOriginal.Foto = bytes;
                    context.SaveChanges();
                }
                else
                {
                    Personas person = new Personas { Id = P.Id, Nombre = P.Nombre, FechaNacimiento = Convert.ToDateTime(P.FechaNac), Foto = bytes };
                    context.Personas.Add(person);
                    context.SaveChanges();
                    //int id = person.Id;
                }
                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
            }
            return View();
        }
Exemple #34
0
                public void RootCompositeWriteRead_Person()  
                {
                    var originalData = new TestPerson{ Name = "Kolyan", DOB = DateTime.Now, Assets=2000000, IsRegistered=true, Luck=150.89};

                    var doc = new PortableObjectDocument(originalData);
                                
                    var convertedData = doc.ToOriginalObject() as TestPerson;
                                
                    Assert.IsFalse( object.ReferenceEquals(originalData, convertedData) );   

                    Assert.IsTrue (originalData.Equals( convertedData ) );
                }
Exemple #35
0
        public void RootClass_TestPerson()
        {
            var date = new DateTime(1981, 12, 01, 14,23, 20,DateTimeKind.Utc);
            var data = new TestPerson { Name="Gagarin", DOB = date, Assets=1000000, IsRegistered=true, Luck=0.02312, Respect=PersonRespect.Guru};

            var json = JW.Write(data);

            Console.WriteLine(json);

            Assert.AreEqual("{\"Assets\":1000000,\"DOB\":\"1981-12-01T14:23:20Z\",\"IsRegistered\":true,\"Luck\":0.02312,\"Name\":\"Gagarin\",\"Respect\":\"Guru\"}", json);
        }