private void AddCatalog(ToolStripMenuItem tsmi) { if (this.InvokeRequired) { AddCatalogItem aci = new AddCatalogItem(AddCatalog); this.Invoke(aci, new object[] { tsmi }); } else { tsCategories.DropDownItems.Add(tsmi); } }
public async Task WhenSendingValidData_ShouldAddSuccessfully() { // Arrange const int catalogTypeId = 1; const int catalogBrandId = 2; const int catalogItemId = 3; var addCatalogItem = new AddCatalogItem("test-name", "test-description", 123.45m, "picture-uri", catalogTypeId, catalogBrandId); var addedCatalogItem = new TestCatalogItem(catalogItemId, catalogTypeId, catalogBrandId, "test-description", "test-name", 123.45m, "picture-uri"); MockGetByIdAsync(catalogTypeId, catalogBrandId, new CatalogType("type-1"), new CatalogBrand("brand-1")); _mockRepository .Setup(x => x.AddAsync(It.IsAny <CatalogItem>())) .ReturnsAsync(addedCatalogItem); // Act var id = await _sut.Handle(addCatalogItem, CancellationToken.None); // Assert id.Should().Be(catalogItemId); }
public async Task WhenSendingInvalidData_ShouldThrow() { // Arrange const int catalogTypeId = 1; const int catalogBrandId = 2; var addCatalogItem = new AddCatalogItem("", "test-description", 123.45m, "picture-uri", catalogTypeId, catalogBrandId); MockGetByIdAsync(catalogTypeId, catalogBrandId, null, null); // Act var task = new Func <Task <int> >(() => _sut.Handle(addCatalogItem, CancellationToken.None)); // Assert var exceptionAssertions = await task.Should().ThrowAsync <ValidationException>(); var errors = exceptionAssertions.ExtractErrorMessages(); errors.Should().Contain($"Catalog Brand with id {catalogBrandId} does not exist in DB"); errors.Should().Contain($"Catalog Type with id {catalogTypeId} does not exist in DB"); }
public async Task WhenFailingToAdd_ShouldThrow() { // Arrange const int catalogTypeId = 1; const int catalogBrandId = 2; var addCatalogItem = new AddCatalogItem("", "test-description", 123.45m, "picture-uri", catalogTypeId, catalogBrandId); MockGetByIdAsync(catalogTypeId, catalogBrandId, new CatalogType("type-1"), new CatalogBrand("brand-1")); _mockRepository .Setup(x => x.AddAsync(It.IsAny <CatalogItem>())) .ThrowsAsync(new Exception("db failure")); // Act var task = new Func <Task <int> >(() => _sut.Handle(addCatalogItem, CancellationToken.None)); // Assert var exceptionAssertions = await task.Should().ThrowAsync <GeneralException>(); var errors = exceptionAssertions.Subject .Select(x => x.Message) .ToList(); errors.Should().Contain($"Failed to add an item"); }