示例#1
0
        public void GetToyById_Return_OK()
        {
            // Arrange
            var mockDb     = new Mock <IDataBaseManager>();
            var mockLogger = new Mock <ILogger>();

            ToysData toy = new ToysData()
            {
                ID = 1, Name = "TyranosaurusRex", Description = "Roarrrrrr", Price = 99
            };

            mockDb.Setup(db => db.IsExistToy(It.IsAny <int>())).Returns(true);
            mockDb.Setup(db => db.GetToyById(It.IsAny <int>())).Returns(toy);
            mockLogger.Setup(db => db.Error(It.IsAny <string>()));

            var manager = new ToysManager(mockDb.Object, mockLogger.Object);

            // Act
            var result = manager.GetToyById(1, out Errors errorCode);

            // Assert
            Assert.AreEqual(Errors.OK, errorCode);
            Assert.AreEqual(toy, result);
            Assert.AreEqual(toy.Name, result.Name);
        }
示例#2
0
        private static void Main()
        {
            var context = new ToysDbContext();
            var db = new ToysData(context);

            var dataManager = new DataManager();
            dataManager.Start();
        }
 /// <summary>
 /// Returns 1 toy with provided ID
 /// </summary>
 /// <param name="toyId"></param>
 public ToysData GetToyById(int toyId)
 {
     using (var con = OpenConnection())
     {
         var      sqlQuery = $"SELECT * FROM Toys WHERE Id = {toyId}";
         ToysData toy      = con.Query <ToysData>(sqlQuery).First();
         return(toy);
     }
 }
示例#4
0
 /// <summary>
 /// Check is that ID is correct and if it is. return toy with that ID
 /// </summary>
 /// <param name="toyId"></param>
 /// <param name="errorCode"></param>
 /// <returns></returns>
 public ToysData GetToyById(int toyId, out Errors errorCode)
 {
     try
     {
         if (!_dbManager.IsExistToy(toyId))
         {
             errorCode = Errors.INVALID_TOY_ID;
             return(null);
         }
         ToysData toy = _dbManager.GetToyById(toyId);
         errorCode = Errors.OK;
         return(toy);
     }
     catch (Exception ex)
     {
         _logger.Error("Data base error", ex);
         errorCode = Errors.DATA_BASE_ERROR;
         return(null);
     }
 }
 public DataManager()
 {
     this.data = new ToysData(this.context);
 }
 public LoadReportsInMySqlDatabaseCommand(ToysData data, ToysDbContext dbContext)
     : base(data)
 {
     this.DbContext = dbContext;
 }