示例#1
0
        /// <summary>
        /// 获取发动机参数
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public EngineViewModel GetEngineOther(string code, string mto)
        {
            TopLineEngineQueueModel queueModel = new TopLineEngineQueueModel
            {
                EngineCode = code,
                EngineMTO  = mto
            };

            if (!string.IsNullOrEmpty(code))
            {
                EngineTypeModel engineType = DbDataCache.GetEngineType(code);
                queueModel.EngineType = engineType?.TypeName;
                if (!string.IsNullOrEmpty(mto))
                {
                    EngineAutoTypeModel autoType = DbDataCache.GetTCaseType(mto);
                    queueModel.TCaseType = autoType?.TCaseType;
                }
                else
                {
                    queueModel = TopLineEngineQueue.Get(code);
                }
            }
            string lmpstr = queueModel.EngineType + " " + queueModel.TCaseType;

            return(EngineViewModel.CreateModel(queueModel.EngineCode, queueModel.EngineMTO, queueModel.EngineType, lmpstr));
        }
示例#2
0
        public int Update(EngineTypeModel model)
        {
            string sqlUpdate = "UPDATE EngineType SET Name = @Name WHERE Id = @Id";

            using (_connection)
            {
                return(_connection.Execute(sqlUpdate, model));
            }
        }
示例#3
0
        public int Insert(EngineTypeModel model)
        {
            string sqlInsert = "INSERT INTO EngineType (Id, Name) Values (@Id, @Name)";

            using (_connection)
            {
                return(_connection.Execute(sqlInsert, model));
            }
        }
示例#4
0
        public int Delete(EngineTypeModel model)
        {
            string sqlDelete = "DELETE FROM EngineType WHERE Id = @Id";

            using (_connection)
            {
                return(_connection.Execute(sqlDelete, model));
            }
        }
示例#5
0
        public void UpdateEngineTypeReturnsBadRequestWhenIdFromModelDoesNotMatchIdFromQueryParameter()
        {
            var invalidModel = new EngineTypeModel
            {
                Id      = 1,
                BrandId = 1
            };

            var brand = new Brand();

            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);

            var result = _sut.UpdateEntity(invalidModel, invalidModel.Id + 1) as BadRequestObjectResult;

            Assert.That(result, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()), Times.Never);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#6
0
        public void PostEngineTypeReturnsNotFoundWhenBrandIsNotFound()
        {
            var validModel = new EngineTypeModel
            {
                Name    = "",
                BrandId = 1
            };

            Brand brand = null;

            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);

            var result = _sut.PostEntity(validModel) as NotFoundObjectResult;

            Assert.That(result, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Add(It.IsAny <EngineType>()), Times.Never);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#7
0
        public void UpdateEngineTypeReturnsBadRequestWhenModelIsInvalid()
        {
            var invalidModel = new EngineTypeModel
            {
                BrandId = 1
            };

            var brand = new Brand();

            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);

            _sut.ModelState.AddModelError("name", "name is required");

            var result = _sut.UpdateEntity(invalidModel, 1) as BadRequestResult;

            Assert.That(result, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()), Times.Never);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#8
0
        public void UpdateEngineTypeReturnsNotFoundWhenModelIsNotFound()
        {
            var invalidModel = new EngineTypeModel
            {
                Id      = 1,
                BrandId = 1
            };

            var brand = new Brand();

            _engineTypeRepositoryMock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()))
            .Returns(false);
            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);

            var result = _sut.UpdateEntity(invalidModel, invalidModel.Id) as NotFoundObjectResult;

            Assert.That(result, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()), Times.Once);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#9
0
        public void UpdateEngineTypeReturnsOkWhenEverythingIsCorrect()
        {
            var validModel = new EngineTypeModel
            {
                Id      = 1,
                Name    = "",
                BrandId = 1
            };

            var brand = new Brand();

            _engineTypeRepositoryMock.Setup(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()))
            .Returns(true);
            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);

            var result = _sut.UpdateEntity(validModel, validModel.Id) as OkResult;

            Assert.That(result, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Update(It.IsAny <int>(), It.IsAny <EngineType>()), Times.Once);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#10
0
        public void PostEngineTypeReturnsOkWhenModelIsValid()
        {
            var validModel = new EngineTypeModel
            {
                Name    = "name",
                BrandId = 1
            };

            var brand = new Brand();

            _brandRepositoryMock.Setup(m => m.GetById(It.IsAny <int>()))
            .Returns(brand);
            _mapperMock.Setup(m => m.Map <EngineTypeReturnModel>(It.IsAny <EngineType>()))
            .Returns(new EngineTypeReturnModel());
            _mapperMock.Setup(m => m.Map <EngineType>(It.IsAny <EngineTypeModel>()))
            .Returns(new EngineType());
            var result = _sut.PostEntity(validModel) as OkObjectResult;

            Assert.That(result, Is.Not.Null);
            Assert.That((EngineTypeReturnModel)result.Value, Is.Not.Null);

            _engineTypeRepositoryMock.Verify(m => m.Add(It.IsAny <EngineType>()), Times.Once);
            _brandRepositoryMock.Verify(m => m.GetById(It.IsAny <int>()), Times.Once);
        }
示例#11
0
 /// <summary>
 /// Method whose purpose is to update
 /// an existing EngineType record.
 /// </summary>
 /// <param name="engineType">
 /// Existing EngineTypeModel object.
 /// </param>
 /// <returns>
 /// Returns true if the query is successfully executed
 /// otherwise returns false.
 /// </returns>
 public bool Update(EngineTypeModel engineType)
 {
     return(_engineTypeRepository.Update(engineType) > 0 ? true : false);
 }
示例#12
0
 /// <summary>
 /// Method whose purpose is to insert
 /// a new EngineType record.
 /// </summary>
 /// <param name="engineType">
 /// Newly created EngineTypeModel object.
 /// </param>
 /// <returns>
 /// Returns true if the query is successfully executed
 /// otherwise returns false.
 /// </returns>
 public bool Insert(EngineTypeModel engineType)
 {
     return(_engineTypeRepository.Insert(engineType) > 0 ? true : false);
 }