public void CreateArticle_When_ArticleDto_isNull_Should_Throw_ArgumentNullException() { // Act Action action = () => { articleService.CreateArticle(null); }; // Assert action.Should().Throw <ArgumentNullException>(); }
public void CreateArticle_InsertingFailed_ThrowDatabaseException() { database.Setup(d => d.ArticleRepository.Insert(It.IsNotNull <Article>(), false)) .ReturnsAsync(false); Assert.That(() => articleService.CreateArticle(createRequest), Throws.Exception.TypeOf <DatabaseException>()); }
public async void NewArticleAdded() { if (CountryName != null && PurchaserUsername != null) { Country country = await CountryService.GetCountryWithName(CountryName); Profile profile = await ProfileService.GetProfileByUsernameAndpassword(PurchaserUsername, "1234"); Purchaser purchaser = await PurchaserService.GetPurchaserForProfile(profile.Id); Article Article = new Article() { PurchaserId = purchaser.Id, SupplierId = Id, CountryId = country.Id, VailedForCustomer = ValidForCustomer, DateCreated = DateTime.Now, ArticleState = (int)ArticleState.Created, ArticleInformation = new ArticleInformation(), InternalArticleInformation = new InternalArticleInformation() }; Article.ArticleInformation.CompanyName = Supplier.CompanyName; Article.ArticleInformation.CompanyLocation = Supplier.CompanyLocation; Article.ArticleInformation.FreightResponsibility = Supplier.FreightResponsibility; Article.ArticleInformation.PalletExchange = Supplier.PalletExchange; Article.ArticleInformation.Email = Supplier.Profile.Username; Article newArticle = await ArticleService.CreateArticle(Article); NavigationManager.NavigateTo($"/supplier_info_form/{newArticle.ArticleInformation.Id}", true); } }
public void CallSaveChanges_WhenInputDataIsValid() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); var id = "some name"; var title = "some name"; var city = "some name"; var country = "some content"; var contentMain = "some content"; var contnentBudget = "some content"; var contentAccomodation = "some content"; var contentMustSee = "some name"; var imageUrl = "some name"; var secondImage = "some name"; var thirdImage = "some name"; string coverImage = "some name"; contextMock.Setup(x => x.Articles.Add(It.IsAny <Article>())); contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns(new User()); var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act service.CreateArticle(id, title, city, country, contentMain, contentMustSee, contnentBudget, contentAccomodation, imageUrl, secondImage, thirdImage, coverImage); // Assert contextMock.Verify(x => x.SaveChanges(), Times.Once); }
public void ThrowInvalidOperationException_WhenNoSuchUserIsFound() { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); var id = "some name"; var title = "some name"; var city = "some name"; var country = "some content"; var contentMain = "some content"; var contnentBudget = "some content"; var contentAccomodation = "some content"; var contentMustSee = "some name"; var imageUrl = "some name"; var secondImage = "some name"; var thirdImage = "some name"; string coverImage = "some name"; contextMock.Setup(x => x.Users.Find(It.IsAny <string>())).Returns((User)null); var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act & Assert var ex = Assert.Throws <InvalidOperationException>(() => service.CreateArticle(id, title, city, country, contentMain, contentMustSee, contnentBudget, contentAccomodation, imageUrl, secondImage, thirdImage, coverImage)); }
public ActionResult Create(ArticleGetViewModel journalView) { if (journalView == null) { return(HttpNotFound()); } if (ModelState.IsValid) { _articleService.CreateArticle(journalView); } return(RedirectToAction("Index")); }
public void CreateArticleValidation(string name, DateTime date, string text) { var mockBlogRepository = new Mock <IBlogRepository>(); mockBlogRepository.Setup(m => m.Articles.Create(It.IsAny <Article>())); var _articleService = new ArticleService(mockBlogRepository.Object); Assert.Throws <ValidationException>(() => _articleService.CreateArticle(new ArticleDTO() { Name = name, Date = date, Text = text })); }
public async Task <IActionResult> Post([FromBody] NewArticleRequest newArticleRequest) { try { var tokenHeader = Request.Headers["Authorization"]; var token = tokenHeader.Count > 0 ? tokenHeader.First().Split(' ')[1] : null; User currentUser = null; if (!string.IsNullOrWhiteSpace(token)) { currentUser = UserService.GetCurrentUser(token); } if (currentUser == null) { return(Unauthorized()); } var article = await ArticleService.CreateArticle(newArticleRequest.Article, token); return(article != null ? Created($"api/articles/{article.Slug}", new SingleArticleResponse { Article = new ArticleModel( article.Slug, article.Title, article.Description, article.Body, article.ArticleTags.Select(t => t.Tag.TagName).ToList(), article.CreatedAt, article.UpdatedAt, article.GetFavorited(currentUser), article.FavoritesCount, article.Author.Profile ) }) : (IActionResult)BadRequest("Not created.")); } catch (Exception ex) { var genericErrorModel = new GenericErrorModel(new GenericErrorModelErrors(new[] { ex.ToString() })); return(BadRequest(genericErrorModel)); } }
public async Task <ActionResult <ClientArticle> > Create([FromBody] ArticleChange change) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(await service.CreateArticle(change, User)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task OnSaveArticleClicked() { Article.Content = await RichTextEditor.GetContentAsync(); if (string.IsNullOrEmpty(Article.Id)) { Article.Id = Guid.NewGuid().ToString(); } if (string.IsNullOrEmpty(Id)) { await ArticleService.CreateArticle(Article); } else { await ArticleService.UpdateArticle(Article); } NavigationManager.NavigateTo("articles"); }
public void CreateArticleShouldReturnFalseForWrongArticleType() { var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase("Database_For_Tests").Options; var dbContext = new ApplicationDbContext(options); var service = new ArticleService(dbContext); var model = new ArticleViewModel { Title = "Title", ArticleImage = "Something", AdditionalContent = "Something", AdditionalContentImage = "Something", Content = "Something", ContentImage = "Something", Type = "Normal", }; var article = service.CreateArticle(model); Assert.False(article); }
public void ThrowArgumentNullException_WhenPassedCountryIsNull(string country) { // Arrange var contextMock = new Mock <ITravelGuideContext>(); var factoryMock = new Mock <IArticleFactory>(); var commentFactoryMock = new Mock <IArticleCommentFactory>(); var id = "some name"; var title = "some name"; var city = "some name"; var contentMain = "some content"; var contnentBudget = "some content"; var contentAccomodation = "some content"; var contentMustSee = "some content"; var imageUrl = "some name"; var secondImage = "some name"; var thirdImage = "some name"; var coverImage = "some name"; var service = new ArticleService(contextMock.Object, factoryMock.Object, commentFactoryMock.Object); // Act & Assert var ex = Assert.Throws <ArgumentNullException>(() => service.CreateArticle(id, title, city, country, contentMain, contentMustSee, contnentBudget, contentAccomodation, imageUrl, secondImage, thirdImage, coverImage)); }
public ActionResult Create(FormCollection form, string submitButton) { ViewData["articleTypeId_0"] = new SelectList(CreateArticleTypeList(0), "Value", "Text"); try { var article = new Articles() { articleTypeId = Convert.ToInt32(form["articleTypeId_0"]), body = form["Body"], dateCreated = DateTime.Now, headline = form["headline"], strapline = form["strapline"] }; _articleService.CreateArticle(article); Publish(form, submitButton, article); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult <Article> Create(Article newArticle) { _articleService.CreateArticle(newArticle); return(CreatedAtRoute("CreatedArticle", newArticle)); }
public async Task <IActionResult> CreateArticle([FromBody] CreateArticleInput input) { var id = await _articleService.CreateArticle(input); return(Created($"/api/v1/articles/{id}", null)); }
public async Task <ActionResult <Article> > Create(Article article) { articleService.CreateArticle(article); return(CreatedAtAction(nameof(GetById), new { id = article.Id }, article)); }
public async Task <IActionResult> CreateArticle([FromBody] ArticleCreateDto createArticle) { var id = await _articleService.CreateArticle(createArticle); return(Created($"api/articles/{id}", id)); }
public async Task UpdateArticleUpdateTheGivenArticle() { // arrange ArticleService articleService = new ArticleService(_client); PurchaserService purchaserService = new PurchaserService(_client); CountryService countryService = new CountryService(_client); SupplierService supplierService = new SupplierService(_client); Article article = new Article() { Id = 0, PurchaserId = 1, CountryId = 1, SupplierId = 1, ArticleInformationId = 0, InternalArticleInformationId = 0, VailedForCustomer = "Customer", DateCreated = DateTime.Now, ArticleInformationCompleted = 0, InternalArticalInformationCompleted = 0, ArticleState = 0, ErrorReported = 0, ErrorField = "Field", ErrorMessage = "Message", ErrorOwner = "Owner", ArticleInformation = new ArticleInformation(), InternalArticleInformation = new InternalArticleInformation() }; Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Supplier supplier = new Supplier() { Id = 0, ProfileId = 0, CompanyName = "Name", CompanyLocation = "Location", FreightResponsibility = "EXW", PalletExchange = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Country countryToDelete = await countryService.CreateCountry(country); purchaser.CountryId = countryToDelete.Id; Purchaser purchaserToDelete = await purchaserService.CreatePurchaser(purchaser); Supplier supplierToDelete = await supplierService.CreateSupplier(supplier); article.CountryId = countryToDelete.Id; article.SupplierId = supplierToDelete.Id; article.PurchaserId = purchaserToDelete.Id; Article expected = await articleService.CreateArticle(article); expected.ArticleState = 3; // act await articleService.UpdateArticle(expected.Id, expected); Article actual = await articleService.GetArticle(expected.Id); // assert Assert.IsTrue(expected.ArticleState == actual.ArticleState); List <Country> now = await countryService.GetCountries(); await articleService.DeleteArticle(expected.Id); await purchaserService.DeletePurchaserForProfile(purchaserToDelete.ProfileId); await supplierService.DeleteSupplier(supplierToDelete.Id); await countryService.DeleteCountry(countryToDelete.Id); await _context.DisposeAsync(); List <Country> late = await countryService.GetCountries(); }