Example #1
0
		static void Main(string[] args)
		{
			Console.WriteLine("Start");

			var container = new ServiceContainer();
			container.Register<IDataBaseController, DataBaseController>();

			IDataBaseController _dbController = container.GetInstance<IDataBaseController>();

			Product p1 = new Product()
			{
				Id = 1
			};

			Product p2 = new Product()
			{
				Id = 2
			};

			Product p3 = null;

			_dbController.InsertProduct(p1);
			_dbController.InsertProduct(p3);
			_dbController.InsertProduct(p2);

			Console.WriteLine("End");

			Console.ReadLine();
		}
		public int InsertProduct(Product createdProduct)
		{
			MyLogger.WriteTraceMessage("Enter in InsertProduct");

			try
			{
				if (createdProduct == null)
				{
					throw new ArgumentNullException("createdProduct");
				}

				_collection.Add(createdProduct);

				return _collection.Contains(createdProduct) ? 1 : 0;
			}
			catch (Exception ex)
			{
				MyLogger.WriteErrorMessage(ex.ToString());
				return 0;
			}
			finally
			{
				MyLogger.WriteTraceMessage("Exit from InsertProduct");
			}
		}
		public void InsertProduct_Returned1()
		{
			//Arrange
			var container = new ServiceContainer();
			container.Register<IDataBaseController, DataBaseController>();

			Product fakeProduct = new Product()
			{
				Id = 100,
				Name = "FooProduct",
				Price = 25
			};

			IDataBaseController dataBaseController = container.GetInstance<IDataBaseController>();

			//Act
			int resultOperation = dataBaseController.InsertProduct(fakeProduct);

			//Assert
			Assert.AreEqual(resultOperation, 1);
		}
		public int UpdateProduct(Product updatedProduct)
		{
			throw new NotImplementedException();
		}
		public int DeleteProduct(Product deletedProduct)
		{
			throw new NotImplementedException();
		}