public void SortRecordsByGenderTest()
        {
            RecordsController recordsController = new RecordsController(_mockRecordService.Object);
            List <RecordDto>  recordsDto        = recordsController.Gender();

            Assert.AreEqual("Female", recordsDto[0].Gender);
        }
Ejemplo n.º 2
0
        public void GenderUnitTest()
        {
            var mockRepo = new Moq.Mock <IRepository <Person> >();

            mockRepo.Setup(aa => aa.AsQueryable()).Returns(PersonList().AsQueryable <Person>());

            var controller = new RecordsController(mockRepo.Object);

            var result = controller.Gender();


            Assert.That(CastIt(result) != null);

            Assert.That(CastIt(result).First().Gender == "female");
            Assert.That(CastIt(result).Last().Gender == "male");
        }
        public void Gender()
        {
            // Arrange
            var mockFileProcessor = new Mock <IRecordService>();

            mockFileProcessor.Setup(x => x.ImportRecords()).Returns(records);

            RecordsController controller = new RecordsController(mockFileProcessor.Object);

            // Act
            IHttpActionResult result = controller.Gender();
            var contentResult        = result as JsonResult <IOrderedEnumerable <Record> >;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(3, contentResult.Content.Count());
            Assert.AreEqual("Female", contentResult.Content.ElementAt(0).Gender);
        }
Ejemplo n.º 4
0
        public static void Test_that_ordering_is_correct( )
        {
            var randomProvider = new Random( );
            var person1        = PreferencesHelpers.GenerateRandomRecord(randomProvider);
            var person1A       = new PersonColorPreferenceModel( ).PopulateFrom(person1);

            person1A.LastName = "person1A";
            var person2  = PreferencesHelpers.GenerateRandomRecord(randomProvider);
            var person3  = PreferencesHelpers.GenerateRandomRecord(randomProvider);
            var person3A = new PersonColorPreferenceModel( ).PopulateFrom(person3);

            person3A.LastName = "person3A";

            var newRecords = new List <PersonColorPreferenceModel>
            {
                person1,
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                person1,
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                person2,
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                person2,
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                person3,
                PreferencesHelpers.GenerateRandomRecord(randomProvider),
                person3
            }.ToSafeList( );

            var target = new RecordsController( );
            var model  = RecordsApiModel.CurrentModel;

            newRecords.ForEach(newRecord => target.PostLine(UnitTestHelpers.GenerateLine(newRecord, '|')));

            model.Add(newRecords);

            var added                = model.PersonColorPreferences.ToSafeList( );
            var byBirthDate          = target.Birthdate( ).ToSafeList( );
            var byGenderLastName     = target.Gender( ).ToSafeList( );
            var byLastNameDescending = target.LastName( ).ToSafeList( );
            var byName               = target.Name( ).ToSafeList( );
            var byGet                = target.Get( ).ToSafeList( );

            added.Aggregate((arg1, arg2) =>
            {
                Assert.True(arg1.Id < arg2.Id);
                return(arg2);
            });

            byGet.Aggregate((arg1, arg2) =>
            {
                Assert.True(arg1.Id < arg2.Id);
                return(arg2);
            });

            byBirthDate.Aggregate((arg1, arg2) =>
            {
                Assert.True(arg1.DateTimeBirth <= arg2.DateTimeBirth);
                return(arg2);
            });

            byGenderLastName.Aggregate((arg1, arg2) =>
            {
                var order = string.Compare(arg1.Gender, arg2.Gender, StringComparison.InvariantCulture);
                Assert.True(order <= 0);
                if (order == 0)
                {
                    var order2 = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture);
                    Assert.True(order2 <= 0);
                }

                return(arg2);
            });

            byLastNameDescending.Aggregate((arg1, arg2) =>
            {
                Assert.True(string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture) >= 0);
                return(arg2);
            });

            byName.Aggregate((arg1, arg2) =>
            {
                var order = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture);
                Assert.True(order <= 0);
                if (order == 0)
                {
                    var order2 = string.Compare(arg1.FirstNameUpper, arg2.FirstNameUpper, StringComparison.InvariantCulture);
                    Assert.True(order2 <= 0);
                }

                return(arg2);
            });
        }