Exemplo n.º 1
0
        public static void Should_throw_a_exception_when_add_a_null_medical_appointment()
        {
            // arrange
            var person = new FakePerson((FakeCode)"code", "name");

            // act & assert
            Assert.Throws <ArgumentNullException>(() => person.AddMedicalAppointment(null));
        }
Exemplo n.º 2
0
        public void Validate_0_ThrowsException()
        {
            var person = new FakePerson();

            var actual = Assert.ThrowsException <InvalidOperationException>(() => person.ValidateIsPositiveValue(0));

            Assert.AreEqual("Value has to be positive", actual.Message);
        }
Exemplo n.º 3
0
        FakePerson GetValidFakePerson()
        {
            FakePerson person = FakePerson.NewFakePerson();

            person.LastName      = "Smith";
            person.HomeTelephone = "01234 567890";

            return(person);
        }
 public void SetUp()
 {
     _converter = new ReferenceTypeConverter<FakePerson>();
     _person = new FakePerson()
     {
         Birthname = "Dexter",
         FamilyName = "Gandini",
         PersonGender = FakePerson.Gender.Male
     };
 }
Exemplo n.º 5
0
 public void SetUp()
 {
     _converter = new ReferenceTypeConverter <FakePerson>();
     _person    = new FakePerson()
     {
         Birthname    = "Dexter",
         FamilyName   = "Gandini",
         PersonGender = FakePerson.Gender.Male
     };
 }
Exemplo n.º 6
0
        public void Get_WhenCalled_ReturnsObjectLocation()
        {
            var fakePerson = new FakePerson()
            {
                Id = 200, FirstName = "Daisy"
            };
            var result = _testPersonController.Post(fakePerson) as CreatedAtActionResult;

            Assert.Equal(201, result.StatusCode);
        }
Exemplo n.º 7
0
        public static void Should_return_false_when_compare_a_person_with_a_non_person()
        {
            // arrange
            var person1 = new FakePerson((FakeCode)"code", "name");

            // act
            var result = person1.Equals(new { });

            // assert
            Assert.False(result);
        }
Exemplo n.º 8
0
        public static void Should_parse_a_person_without_medical_appointments_into_a_string()
        {
            // arrange
            var person = new FakePerson((FakeCode)"code", "name");

            // act
            var result = person.ToString();

            // assert
            Assert.Equal("Código: code - Nome: name - Consultas: [] - Valor Total: 0", result);
        }
Exemplo n.º 9
0
    void Start()
    {
        manager = FindObjectOfType <GameManager>().GetComponent <GameManager>();
        CheckFirstLaunch();
        InitList();

        FakePerson person = people[Random.Range(0, people.Count)];
        var        sb     = new System.Text.StringBuilder();

        sb.Append("You got " + manager.points + " points" + System.Environment.NewLine + "Your Record: " + PlayerPrefs.GetInt("high_score", 0) + " points" + System.Environment.NewLine + person.name + "'s record: " + person.score + " points");
        scoreRecordPersonText.text = sb.ToString();
    }
Exemplo n.º 10
0
        public void Post_WhenCalledWithoutLastName_GeneratesBadRequestResponse()
        {
            //Arrange
            _testPersonController.ModelState.AddModelError("LastName", "Required");
            var fakePerson = new FakePerson()
            {
                Id = 200, FirstName = "Daisy"
            };
            var result = _testPersonController.Post(fakePerson);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemplo n.º 11
0
        public void SetValidatorToNewValidator_WhenPassedValidatorIsValid()
        {
            // arrange
            string firstName = "ValidName";
            string lastName  = "ValidName";

            // act
            var person = new FakePerson(firstName, lastName);

            // assert
            Assert.IsInstanceOf <Validator>(person.ValidatorExposed);
        }
Exemplo n.º 12
0
        public static void HashCode_should_be_code()
        {
            // arrange
            var code   = (FakeCode)"code";
            var person = new FakePerson(code, "name");

            // act
            var result = person.GetHashCode();

            // assert
            Assert.Equal(code.GetHashCode(), result);
        }
Exemplo n.º 13
0
        public static void Should_return_true_when_compare_two_equal_people()
        {
            // arrange
            var person1 = new FakePerson((FakeCode)"code", "name");
            var person2 = new FakePerson((FakeCode)"code", "name");

            // act
            var result = person1.Equals(person2);

            // assert
            Assert.True(result);
        }
Exemplo n.º 14
0
        public static void Should_return_true_when_compare_two_different_people(string code, string name)
        {
            // arrange
            var person1 = new FakePerson((FakeCode)"code", "name");
            var person2 = new FakePerson((FakeCode)code, name);

            // act
            var result = person1.Equals(person2);

            // assert
            Assert.False(result);
        }
Exemplo n.º 15
0
        public void Post_WhenCalled_Returns201ObjectCreatedResult()
        {
            //Arrange
            var fakePerson = new FakePerson()
            {
                Id = 2, FirstName = "Alice", LastName = "Norton"
            };
            //Act
            var result = (CreatedAtActionResult)_testPersonController.Post(fakePerson);

            //Assert
            Assert.Equal(201, result.StatusCode);
        }
Exemplo n.º 16
0
        public void SetValidatorToThePassedValidator_WhenPassedValidtorIsValid()
        {
            // arrange
            string firstName = "ValidName";
            string lastName  = "ValidName";
            var    validator = new Mock <IValidator>();

            // act
            var person = new FakePerson(firstName, lastName, validator.Object);

            // assert
            Assert.AreSame(validator.Object, person.ValidatorExposed);
        }
Exemplo n.º 17
0
        public static void Should_create_a_valid_person()
        {
            // arrange
            var code = (FakeCode)"code";
            var name = "name";

            // act
            var person = new FakePerson(code, name);

            // assert
            Assert.Equal(code, person.Code);
            Assert.Equal(name, person.Name);
            Assert.True(person.MedicalAppointments.IsEmpty());
        }
Exemplo n.º 18
0
        public static void Should_add_a_medical_appointment()
        {
            // arrange
            var person             = new FakePerson((FakeCode)"code", "name");
            var doctor             = new Doctor((Crm)"12345", "name", MedicalSpecialty.GeneralClinic);
            var customer           = new Customer((Cpf)"012345678-90", "name", CustomerType.Normal);
            var medicalAppointment = new MedicalAppointment(DateTime.Now, MedicalAppointmentType.OnDemand, customer, doctor);

            // act
            person.AddMedicalAppointment(medicalAppointment);

            // assert
            Assert.True(!person.MedicalAppointments.IsEmpty());
            Assert.True(person.MedicalAppointments.Count() == 1);
        }
Exemplo n.º 19
0
        public void ValidateModel_EmptyChildEmailAddress_OneValidationMessage()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Create a new child object (which is immediately invalid)
            person.EmailAddresses.AddNew();

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages();

            // Assert
            Assert.AreEqual(1, messages.Count(), "Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
        }
Exemplo n.º 20
0
        public static void Should_parse_a_person_with_medical_appointments_into_a_string()
        {
            // arrange
            var person              = new FakePerson((FakeCode)"code", "name");
            var doctor              = new Doctor((Crm)"12345", "name", MedicalSpecialty.GeneralClinic);
            var customer            = new Customer((Cpf)"012345678-90", "name", CustomerType.Normal);
            var medicalAppointment1 = new MedicalAppointment(DateTime.Now, MedicalAppointmentType.OnDemand, customer, doctor);
            var medicalAppointment2 = new MedicalAppointment(DateTime.Now, MedicalAppointmentType.OnDemand, customer, doctor);

            person.AddMedicalAppointment(medicalAppointment1);
            person.AddMedicalAppointment(medicalAppointment2);

            // act
            var result = person.ToString();

            // assert
            Assert.Equal($"Código: code - Nome: name - Consultas: [{medicalAppointment1},{medicalAppointment2}] - Valor Total: 0", result);
        }
Exemplo n.º 21
0
        public void ValidateModel_EmptyLastName_OneValidationMessage()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set last name to an invalid value
            person.LastName = string.Empty;

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages();

            // Assert
            Assert.AreEqual(1, messages.Count(), "Incorrect number of validation messages returned!");
        }
Exemplo n.º 22
0
        public void ValidateModel_ShortLastName_NoValidationMessages()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set last name to an invalid value
            person.LastName = "A";

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages();

            // Assert
            Assert.AreEqual(0, messages.Count(), "Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
        }
Exemplo n.º 23
0
        public void ValidateField_ShortLastName_NoValidationMessagesForLastName()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set both last name to an invalid value
            person.LastName = "A";

            // Act
            editContext.NotifyFieldChanged(new FieldIdentifier(person, nameof(person.LastName)));
            IEnumerable <string> messages = editContext.GetValidationMessages(new FieldIdentifier(person, nameof(person.LastName)));

            // Assert
            Assert.AreEqual(0, messages.Count(), "Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
        }
Exemplo n.º 24
0
        public void ValidateField_NeitherTelephoneProvided_OneValidationMessageForHomeTelephone()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set both phone numbers to invalid values
            person.HomeTelephone   = "";
            person.MobileTelephone = "";

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages(new FieldIdentifier(person, "HomeTelephone"));

            // Assert
            Assert.AreEqual(1, messages.Count(), "Incorrect number of validation messages returned!");
        }
Exemplo n.º 25
0
        public void ValidateModel_NeitherTelephoneProvided_TwoValidationMessages()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set both phone numbers to invalid values
            person.HomeTelephone   = "";
            person.MobileTelephone = "";

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages();

            // Assert
            Assert.AreEqual(2, messages.Count(), "Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
        }
Exemplo n.º 26
0
        public void ValidateField_ExcessiveFirstNameEmptyLastName_OneValidationMessageForFirstName()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Set first and last names to invalid values
            person.FirstName = "This text is more than twenty five characters long";
            person.LastName  = string.Empty;

            // Act
            editContext.Validate();
            IEnumerable <string> messages = editContext.GetValidationMessages(new FieldIdentifier(person, "FirstName"));

            // Assert
            Assert.AreEqual(1, messages.Count(), "Incorrect number of validation messages returned!");
        }
Exemplo n.º 27
0
        public void ValidateField_ValidEmailAddress1_NoValidationMessagesForEmailAddress1()
        {
            // Arrange
            FakePerson  person      = GetValidFakePerson();
            EditContext editContext = new EditContext(person);

            editContext.AddCslaValidation();

            // Add a new, valid email address
            FakePersonEmailAddress address = person.EmailAddresses.AddNew();

            address.EmailAddress = "*****@*****.**";

            // Act
            editContext.NotifyFieldChanged(new FieldIdentifier(address, nameof(address.EmailAddress)));
            IEnumerable <string> messages = editContext.GetValidationMessages(new FieldIdentifier(address, nameof(address.EmailAddress)));

            // Assert
            Assert.AreEqual(0, messages.Count(), "Incorrect number of validation messages returned! " + ConcatenateMessages(messages));
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            var p = new FakePerson();

            foreach (var item in p.getAll())
            {
                Console.WriteLine("name" + item.FirstName + "active" + item.IsActive);
            }
            Console.WriteLine("---------------------");
            Console.WriteLine();
            PersonDeactivation deactivation = new PersonDeactivation(p, new EventDispatcher());

            deactivation.Execute(1);
            foreach (var item in p.getAll())
            {
                Console.WriteLine("name" + item.FirstName + "active" + item.IsActive);
            }
            Console.WriteLine("---------------------");
            Console.WriteLine();
            Console.ReadKey();
            Console.WriteLine("Hello World!");
        }
Exemplo n.º 29
0
 public void PersonSetUp()
 {
     _person = new FakePerson("Jon", "Snow", "Male");
 }
Exemplo n.º 30
0
 protected bool Equals(FakePerson other)
 {
     return(string.Equals(FamilyName, other.FamilyName) && string.Equals(Birthname, other.Birthname) && PersonGender == other.PersonGender);
 }
        public void GetPartialResponse_ComplexObjectWithNestedLists_ResultContainsOnlySelectedFields()
        {
            //I don't particularly like this test. I am open to ideas for improvement.
            //This complex test may be a code smell that PartialResponsinator needs to be refactored and broken up.
            const string uriField = "Uri";
            const string salaryField = "Salary";
            const string firstField = "First";
            const string lastField = "Last";
            const string childrenNamesFiled = "ChildrenNames";
            const string personField = "Person";
            const string linksField = "Links";

            const string janeDoeHomepageUri = "http://janedoe.com/";
            const decimal janeDoeSalary = 100000000581.00m;
            const string janeDoeFirstName = "Jane";
            const string janeDoeLastName = "Doe";
            const string deeDoeFirstName = "Dee";
            const string deeDoeLastName = "Doe";

            var namesOfChildren = new List<FakeName> { new FakeName { First = deeDoeFirstName, Last = deeDoeLastName } };
            var person = new FakePerson
            {
                Name = new FakeName {First = janeDoeFirstName, Last = janeDoeLastName},
                ChildrenNames = namesOfChildren
            };

            var links = new List<FakeLink>
            {
                new FakeLink
                {
                    Rel = "homepage",
                    Uri = janeDoeHomepageUri
                }
            };

            var propertyValues = new Dictionary<string, object>();
            propertyValues[uriField] = janeDoeHomepageUri;
            propertyValues[salaryField] = janeDoeSalary;
            propertyValues[childrenNamesFiled] = namesOfChildren;
            propertyValues[personField] = person;
            propertyValues[firstField] = janeDoeFirstName;
            propertyValues[lastField] = janeDoeLastName;
            propertyValues[linksField] = links;

            var fakDto = new FakeDto
            {
                Salary = janeDoeSalary,
                Person = person,
                Links = links
            };

            var partialFieldSelectors = new List<FieldSelectorTreeNode>
            {
                new FieldSelectorTreeNode("Salary"),
                new FieldSelectorTreeNode("Person")
                {
                    Children = new List<FieldSelectorTreeNode>
                    {
                        new FieldSelectorTreeNode("ChildrenNames")
                    }
                },
                new FieldSelectorTreeNode("Links")
                {
                    Children = new List<FieldSelectorTreeNode>
                    {
                        new FieldSelectorTreeNode("Uri")
                    }
                }
            };

            var factory = MockRepository.GenerateStub<IPropertyValueGetterFactory>();
            factory.Stub(x => x.CreatePropertyValueGetter(null, null)).IgnoreArguments().Return(null).WhenCalled(x =>
            {
                var getter = MockRepository.GenerateStub<IPropertyValueGetter>();
                getter.Stub(g => g.PropertyName).Return((string) x.Arguments[1]);
                getter.Stub(g => g.GetPropertyValue(null)).IgnoreArguments().Return(propertyValues[(string)x.Arguments[1]]);
                x.ReturnValue = getter;
            });

            var responsinator = new PartialResponsinator(partialFieldSelectors, factory);
            dynamic partialResponse = responsinator.GetPartialResponse(fakDto);

            Assert.Equal(janeDoeSalary, partialResponse.Salary);

            Assert.Equal(1, partialResponse.Person.ChildrenNames.Count);
            Assert.Equal(deeDoeFirstName, partialResponse.Person.ChildrenNames[0].First);
            Assert.Equal(deeDoeLastName, partialResponse.Person.ChildrenNames[0].Last);

            var firstLink = partialResponse.Links[0] as IDictionary<string, object>;
            Assert.Equal(1, partialResponse.Links.Count);
            Assert.Equal(janeDoeHomepageUri, firstLink["Uri"]);
            Assert.False(firstLink.ContainsKey("Rel"), "Rel should not be present on link.");

            var actualPerson = partialResponse.Person as IDictionary<string, object>;
            Assert.False(actualPerson.ContainsKey("Name"), "Name should not be present on Person");
        }
Exemplo n.º 32
0
 protected bool Equals(FakePerson other)
 {
     return string.Equals(FamilyName, other.FamilyName) && string.Equals(Birthname, other.Birthname) && PersonGender == other.PersonGender;
 }