public void InsertNewProduct() { var product = createNewProduct(); using (var connection = new MsSqlConnectionFactory().Create()) { new ProductRepository(connection).Save(product); } Assert.AreEqual(product.Id, 1); }
public void TearDown() { using (var connection = new MsSqlConnectionFactory().Create()) { using (var command = connection.CreateCommand()) { command.CommandText = "DROP TABLE [dbo].[Products]"; command.ExecuteNonQuery(); } } }
public void InsertNewProductAndGetItById() { var product = createNewProduct(); using (var connection = new MsSqlConnectionFactory().Create()) { new ProductRepository(connection).Save(product); Assert.AreEqual(product.Id, 1); var loadedProduct = new ProductRepository(connection).Get(1); Assert.AreEqual(JsonConvert.SerializeObject(product), JsonConvert.SerializeObject(loadedProduct)); } }
public void UpdateInsertedProduct() { var product = createNewProduct(); using (var connection = new MsSqlConnectionFactory().Create()) { new ProductRepository(connection).Save(product); } Assert.AreEqual(product.Id, 1); product.Description = "Описание товара ..."; product.CategoryCode = 2; product.Name = product.Name + " Update"; using (var connection = new MsSqlConnectionFactory().Create()) { new ProductRepository(connection).Save(product); var loadedProduct = new ProductRepository(connection).Get(1); Assert.AreEqual(JsonConvert.SerializeObject(product), JsonConvert.SerializeObject(loadedProduct)); } }
public void Setup() { using (var connection = new MsSqlConnectionFactory().Create()) { using (var command = connection.CreateCommand()) { command.CommandText = @" CREATE TABLE [dbo].[Products]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NOT NULL, [Description] [nvarchar](256) NULL, [Price] [decimal](15, 2) NOT NULL, [CategoryCode] [int] NOT NULL, CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]"; command.ExecuteNonQuery(); } } }
public void GetByIdNotExistingProduct() { using (var connection = new MsSqlConnectionFactory().Create()) { var ex = Assert.Throws<Exception>(() => new ProductRepository(connection).Get(-1)); Assert.That(ex.Message, Is.EqualTo("Select error: Object not found")); } }
public void SelectAllProucts() { using (var connection = new MsSqlConnectionFactory().Create()) { int count = 3; for (int i = 0; i < count; i++) { var product = createNewProduct(); new ProductRepository(connection).Save(product); Assert.AreEqual(product.Id, i + 1); } var products = new ProductRepository(connection).GetAll(); Assert.AreEqual(products.Count, count); } }
public void SelectAllProuctsFromEmptyTable() { using (var connection = new MsSqlConnectionFactory().Create()) { var products = new ProductRepository(connection).GetAll(); Assert.AreEqual(products.Count, 0); } }
public void RoundProductPrice() { var product = createNewProduct(); product.Price = 123.456m; using (var connection = new MsSqlConnectionFactory().Create()) { new ProductRepository(connection).Save(product); Assert.AreEqual(product.Id, 1); var loadedProduct = new ProductRepository(connection).Get(1); Assert.AreEqual(loadedProduct.Price, 123.46m); } }
public void UpdateDeletedProduct() { var product = createNewProduct(); product.Id = 1; using (var connection = new MsSqlConnectionFactory().Create()) { var ex = Assert.Throws<Exception>(() => new ProductRepository(connection).Save(product)); Assert.That(ex.Message, Is.EqualTo("Update error: Object not found")); } }