Esempio n. 1
0
        public void FilterBy_ShouldReturnMotorsFilteredByAllParameters()
        {
            var motorFamilies = new List <MotorFamily>()
            {
                MotorFamily.VOLVO, MotorFamily.Ford
            };
            var features = new List <string>()
            {
                "F", "", "H", "EMD"
            };
            var displacements = new List <uint?>()
            {
                120, 200, 250
            };

            var expectedMotors = new List <Motor>()
            {
                motorsExamples1[0], motorsExamples1[3], motorsExamples1[7]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, motorFamilies, GetAllDisplacements(), GetAllFeatures());

            Assert.Equal(expectedMotors.OrderBy(m => m.MotorNumber), result.OrderBy(m => m.MotorNumber));
        }
Esempio n. 2
0
        public void FindSimilar_ShouldFindTwoResults()
        {
            List <Motor> allMotors = new List <Motor>()
            {
                motorsExamples1[0], motorsExamples1[1], motorsExamples1[2]
            };
            Motor compared = motorsExamples2[0];

            //TODO: Refactor the data initiation - should be common list of motors with BOM and second list should be it's depp-copy with changed bom afterwards
            allMotors[0].AddPart(partsExamples[0], 1, 1);
            allMotors[0].AddPart(partsExamples[1], 2, 1);
            allMotors[0].AddPart(partsExamples[2], 2, 1);
            allMotors[1].AddPart(partsExamples[3], 3, 1);
            allMotors[1].AddPart(partsExamples[4], 4, 1);
            allMotors[1].AddPart(partsExamples[5], 5, 1);
            allMotors[2].AddPart(partsExamples[0], 3, 1);
            allMotors[2].AddPart(partsExamples[2], 4, 1);
            allMotors[2].AddPart(partsExamples[4], 5, 1);

            compared.AddPart(partsExamples[0], 1, 1);
            compared.AddPart(partsExamples[1], 2, 1);
            compared.AddPart(partsExamples[3], 2, 1);

            List <KeyValuePair <int, Motor> > expected = new List <KeyValuePair <int, Motor> >();

            expected.Add(new KeyValuePair <int, Motor>(1, allMotors[0]));
            expected.Add(new KeyValuePair <int, Motor>(2, allMotors[1]));
            expected.Add(new KeyValuePair <int, Motor>(2, allMotors[2]));

            MotorService motorService = new MotorService(new DataAccessByMemoryCache());

            List <KeyValuePair <int, Motor> > actual = motorService.FindSimilar(compared, allMotors);

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void PartsFilterByDesignations_ShouldReturnAllRecordsIfDesignationIsNullO()
        {
            var expectedParts = partsExamples;

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var expected     = motorService.PartsFilterByDesignations(partsExamples, null);

            Assert.Equal(expectedParts.OrderBy(m => m.PartNumber), expected.OrderBy(m => m.PartNumber));
        }
Esempio n. 4
0
        public void FilterBy_ShouldThrowExceptionIfParametersAreNulls()
        {
            IEnumerable <MotorFamily> families      = null;
            IEnumerable <uint?>       displacements = null;
            IEnumerable <string>      features      = null;

            var motorService = new MotorService(new DataAccessByMemoryCache());

            Assert.Throws <ArgumentNullException>(() => motorService.MotorsFilterBy(motorsExamples1, families, displacements, features));
        }
Esempio n. 5
0
        public void FilterBy_ShouldReturnEmptyCollectionIfParametersAreEmptyCollections()
        {
            List <MotorFamily> families      = new List <MotorFamily>();
            List <uint?>       displacements = new List <uint?>();
            List <string>      features      = new List <string>();

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, families, displacements, features);

            Assert.Empty(result);
        }
Esempio n. 6
0
        public void PartsFilterByDesignations_ShouldReturnCorrectResult()
        {
            var designations = new List <string>()
            {
                "NUT"
            };
            var expectedParts = new List <Part>()
            {
                partsExamples[2], partsExamples[3]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.PartsFilterByDesignations(partsExamples, designations);

            Assert.Equal(expectedParts.OrderBy(m => m.PartNumber), result.OrderBy(m => m.PartNumber));
        }
Esempio n. 7
0
        public void FilterBy_ShouldReturnMotorsFilteredByFeatures()
        {
            var features = new List <string>()
            {
                "F", ""
            };
            var expectedMotors = new List <Motor>()
            {
                motorsExamples1[1], motorsExamples1[2]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, GetAllFamilies(), GetAllDisplacements(), features);

            Assert.Equal(expectedMotors.OrderBy(m => m.MotorNumber), result.OrderBy(m => m.MotorNumber));
        }
Esempio n. 8
0
        public void FilterBy_ShouldReturnMotorsFilteredByDisplacements()
        {
            var displacements = new List <uint?>()
            {
                200, 250
            };
            var expectedMotors = new List <Motor>()
            {
                motorsExamples1[0], motorsExamples1[1], motorsExamples1[4], motorsExamples1[6], motorsExamples1[7]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, GetAllFamilies(), displacements, GetAllFeatures());

            Assert.Equal(expectedMotors.OrderBy(m => m.MotorNumber), result.OrderBy(m => m.MotorNumber));
        }
Esempio n. 9
0
        public void FilterBy_ShouldReturnMotorsFilteredByFamilies()
        {
            var motorFamilies = new List <MotorFamily>()
            {
                MotorFamily.Toyota
            };
            var expectedMotors = new List <Motor>()
            {
                motorsExamples1[4]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, motorFamilies, GetAllDisplacements(), GetAllFeatures());

            Assert.Equal(expectedMotors.OrderBy(m => m.MotorNumber), result.OrderBy(m => m.MotorNumber));
        }
Esempio n. 10
0
        public void PartsFilterBy_ShouldReturnPartsFilteredByDescriptionsAndDesignations()
        {
            var designations = new List <string>()
            {
                "SHAFT"
            };
            var descriptions = new List <string>()
            {
                "Conical"
            };
            var expectedParts = new List <Part>()
            {
                partsExamples[0], partsExamples[5]
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.PartsFilterBy(partsExamples, designations, descriptions);

            Assert.Equal(expectedParts.OrderBy(m => m.PartNumber), result.OrderBy(m => m.PartNumber));
        }
Esempio n. 11
0
        public void FilterBy_ShouldReturnEmptyCollectionIfNothingFound()
        {
            var features = new List <string>()
            {
                "Not existing feature"
            };
            var displacements = new List <uint?>()
            {
                404
            };
            var families = new List <MotorFamily>()
            {
                MotorFamily.VOLVO
            };

            var motorService = new MotorService(new DataAccessByMemoryCache());
            var result       = motorService.MotorsFilterBy(motorsExamples1, families, displacements, features);

            Assert.Empty(result);
            Assert.NotNull(result);
        }
Esempio n. 12
0
 public DCMotorController(ILogger <DCMotorController> logger, MotorService motorService)
 {
     _logger       = logger;
     _motorService = motorService;
 }