Пример #1
0
        public void SortedByMake_ShouldReturnACollectionSortedInAlphabeticalOrder()
        {
            // Arrange

            // Step 1: Build list of cars
            var dbListOfCars = new List <Car>();

            for (int i = 0; i < 26; i++)
            {
                var newCar = new FakeCar();
                newCar.Make = ((char)('z' - i)).ToString();
                //newCar.SetupGet(car => car.Make).Returns(((char)('z' - i)).ToString());
                dbListOfCars.Add(newCar);
            }

            // Step 2: Init Database and CarRepo
            var mockDb = new Mock <IDatabase>();

            mockDb.SetupGet(db => db.Cars).Returns(dbListOfCars);

            var carRepo = new CarsRepository(mockDb.Object);

            // Act
            var actualSortedList = carRepo.SortedByMake();
            var expected         = "a";

            Assert.AreEqual(expected, (actualSortedList.First()).Make);
        }
Пример #2
0
        public void SortedByYear_ShouldReturnACollectionSortedInAlphabeticalOrder()
        {
            // Arrange

            var dbListOfCars = new List <Car>();

            for (int i = 0; i <= 26; i++)
            {
                var newCar = new FakeCar();
                newCar.Year = 1990 + i;
                dbListOfCars.Add(newCar);
            }

            var mockDb = new Mock <IDatabase>();

            mockDb.SetupGet(db => db.Cars).Returns(dbListOfCars);

            var carRepo = new CarsRepository(mockDb.Object);

            // Act
            var actualSortedList = carRepo.SortedByYear();
            var expected         = 2016;

            Assert.AreEqual(expected, (actualSortedList.First()).Year);
        }
        public void Add_CarParameterMakeOrModelAreNull_ShouldThrowTheCorrectExceptionMessage()
        {
            var actual = false;

            Car car        = new FakeCar();
            var controller = new CarsController();

            try
            {
                controller.Add(car);
            }
            catch (ArgumentNullException ex)
            {
                actual = ex.Message.Contains("Car make and model cannot be empty");
            }

            Assert.IsTrue(actual);
        }
Пример #4
0
            internal async void ProcessAsync(object sender, EventArgs e)
            {
                try
                {
                    if (!Enabled)
                    {
                        return;
                    }

                    Logger.Debug("{0}光栅触发", scaleOperator.Name);

                    if (IsBusy)
                    {
                        return;
                    }
                    IsBusy = true;
                    Busy?.Invoke(this, new EventArgs());

                    await scaleOperator.SwitchRelayAsync(false);//turn red

                    double        weight = 0;
                    GetWtResponse resp   = null;
                    for (int i = 1; i <= 5; i++)
                    {
                        Logger.Debug("[{0}]请求重量", scaleOperator.Name);
                        resp = await scaleOperator.RestClient.GetWtAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString());

                        Logger.Debug("[{0}]返回重量{1}", scaleOperator.Name, resp.wt_num);

                        /*GetWtResponse resp = new GetWtResponse()
                         * {
                         *  status = "1",
                         *  tk_no = "辽A 88888888",
                         *  wt_num = "1000.88"
                         * };*/
                        if (resp.status == "0")
                        {
                            //Progress?.Invoke(this, new ProgressEventArgs("请求重量失败"));
                            Logger.Warn("称重失败");
                            await Task.Delay(1000);

                            continue;
                        }
                        var w = Convert.ToDouble(resp.wt_num);
                        if (w > 1000)
                        {
                            Logger.Debug("称重大于1000");
                            weight = w;
                            break;
                        }
                        await Task.Delay(1000);
                    }
                    if (weight < 1000)
                    {
                        Logger.Debug("称重小于1000, 开始抬杆");
                        Logger.Debug("[{0}]请求抬杆", scaleOperator.Name);
                        GatePassResponse gpResp = await scaleOperator.RestClient.GatePassAsync(scaleOperator.ScaleIP, scaleOperator.InOrOut.ToString(), resp.tk_no, resp.wt_num);

                        Logger.Debug("[{0}]返回抬杆", scaleOperator.Name);

                        /*GatePassResponse gpResp = new GatePassResponse()
                         * {
                         *  status = 1
                         * };*/
                        if (gpResp.status == "0")//抬杆失败
                        {
                            //Progress?.Invoke(this, new ProgressEventArgs("抬杆失败"));
                            Logger.Warn("抬杆失败:" + gpResp.reason);
                            //SwitchRelay(false);//no need to call this, it's already red
                        }
                        else if (gpResp.status == "1")
                        {
                            Logger.Info("抬杆成功");
                            //Progress?.Invoke(this, new ProgressEventArgs("抬杆成功"));
                            //SwitchRelay(true);
                        }
                        FakeCar?.Invoke(this, new EventArgs());
                    }
                }
                catch (Exception ex)
                {
                    Error?.Invoke(this, new EventArgs());
                    Logger.Debug("处理前光栅事件发生异常:{0}", ex.Message);
                }
                finally
                {
                    IsBusy = false;
                }
            }