public Task <Author> Create(AuthorDto newAuthor) { MethodBase m = MethodBase.GetCurrentMethod(); Devon4NetLogger.Debug($"{m.ReflectedType.Name} method from repository " + $"BookService with value : {newAuthor}"); var author = new Author { Name = newAuthor._name, Surname = newAuthor._surname, Email = newAuthor._email, Phone = newAuthor._phone }; #if ENABLE // TODO: Add it correctly var result = AuthorValidator.Validate(newAuthor); if (!result.IsValid) { throw new ArgumentException($"The 'Description' field can not be null.{result.Errors}"); } #endif return(Create(author)); }
public async Task UpdateAuthor(AuthorDto input) { List <string> errorList = new List <string>(); var data = await GetAuthorById(input.Id); data.Name = input.Name; data.Address = input.Address; data.Phone = input.Phone; AuthorValidator validator = new AuthorValidator(); ValidationResult validationResult = validator.Validate(data); if (!validationResult.IsValid) { foreach (var failure in validationResult.Errors) { errorList.Add(string.Format("{0}", failure.ErrorMessage)); } string errorString = string.Join(" ", errorList.ToArray()); throw new UserFriendlyException(errorString); } await _authorRepository.UpdateAsync(data); }
public static void SeedDb(IConfiguration configuration) { var services = new ServiceCollection(); services.AddDbContext <AppDbContext>(o => o.UseSqlServer(configuration.GetConnectionString("Default"))); var serviceProvider = services.BuildServiceProvider(); using (serviceProvider.CreateScope()) { var context = serviceProvider.GetService <AppDbContext>(); var user = new User("Test"); var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(context); var author = Author.Create(user, authorProfile, authorValidator).Result; for (var i = 0; i < 20; i++) { var blogPostContent = new BlogPostContent("This is a test subject.", "Let's begin with a test intro", "And here's the test content"); var category = new Category("Test", 1, "Test description"); var blogPost = new BlogPost(blogPostContent, author, category); context.BlogPosts.Add(blogPost); } context.SaveChanges(); } serviceProvider.Dispose(); }
public AuthorValidatorTests() { _mockUserInfoService = new Mock <IUserInfoService>(); _validator = new AuthorValidator(_mockUserInfoService.Object); _metadata = new MetadataBuilder().GenerateSampleAuthor().Build(); }
public async Task AddAuthor(AuthorDto input) { List <string> errorList = new List <string>(); var author = new Author { Name = input.Name, YearOfBirth = input.YearOfBirth, Address = input.Address, Phone = input.Phone }; AuthorValidator validator = new AuthorValidator(); ValidationResult validationResult = validator.Validate(author); if (!validationResult.IsValid) { foreach (var failure in validationResult.Errors) { errorList.Add(string.Format("{0}", failure.ErrorMessage)); } string errorString = string.Join(" ", errorList.ToArray()); throw new UserFriendlyException(errorString); } await _authorRepository.InsertAsync(author); }
public async Task AddAuthorCommandHandler_WithExperiences_ReturnsAuthor() { var image = await AddImage(); var experiences = new List <ExperienceDto>(); var experienceDto = new ExperienceDto() { Color = "#000000", Name = "Testfile", ImageId = image.Id }; experiences.Add(experienceDto); var authorValidator = new AuthorValidator(RequestDbContext); var addAuthorCommandHandler = new AddAuthorCommandHandler(TestContext.CreateHandlerContext <AuthorViewModel>(RequestDbContext, CreateMapper()), _userService, authorValidator); var message = new AddAuthorCommand() { FirstName = "Tom", LastName = "Bina", About = "About me", Experiences = experiences }; var result = await addAuthorCommandHandler.Handle(message, CancellationToken.None); Assert.Equal("Testfile", result.Experiences.First().Name = experienceDto.Name); }
public override async Task InitializeAsync() { using (var context = TestContext.CreateNewContext()) { var user = new User("Test"); var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(RequestDbContext); var author = await Author.Create(user, authorProfile, authorValidator); await context.SaveChangesAsync(); for (var i = 0; i < 2; i++) { var dateRange = new DateRange(new DateTime(2017, 1, 1), new DateTime(2017, 1, 2)); var resumeEvent = new ResumeEvent(author, dateRange, "Test", "Test"); context.ResumeEvents.Add(resumeEvent); await context.SaveChangesAsync(); } await context.SaveChangesAsync(); var userService = new Mock <IUserService>(); userService.Setup(exp => exp.GetOrCreateCurrentUserAsync()).ReturnsAsync(user); userService.Setup(exp => exp.TryGetCurrentUserAsync()).ReturnsAsync(user.ToSuccessResult()); _userService = userService.Object; _authorService = new AuthorService(_userService, RequestDbContext); } }
private static void ValidateAuthor(Author author) { var validator = new AuthorValidator(); var results = validator.Validate(author); if (results.IsValid) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Author are successfully validated."); Console.ForegroundColor = ConsoleColor.Gray; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Failed. Errors:"); Console.ForegroundColor = ConsoleColor.DarkRed; foreach (ValidationFailure failure in results.Errors) { Console.WriteLine(failure.ErrorMessage); } Console.ForegroundColor = ConsoleColor.Gray; } Console.WriteLine(); }
static Validators() { AuthorValidator = new AuthorValidator(); BookValidator = new BookValidator(); PublisherValidator = new PublisherValidator(); PaperValidator = new PaperValidator(); PatentValidator = new PatentValidator(); PaperIssueValidator = new PaperIssueValidator(); }
public RegisterForm() { InitializeComponent(); _authorValidator = new AuthorValidator(); // Αλλάζουμε το format της ημερομηνίας dobDateTimePicker.Format = DateTimePickerFormat.Custom; dobDateTimePicker.CustomFormat = "dd/MM/yyyy"; }
private async Task AddAuthor() { using (var context = TestContext.CreateNewContext()) { var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(context); var user = await _userService.GetOrCreateCurrentUserAsync(); var author = await Author.Create(user, authorProfile, authorValidator); context.Authors.Add(author); await context.SaveChangesAsync(); } }
public async Task AddAuthorCommandHandler_AddingSecondTime_ThrowsException() { await AddAuthor(); var authorValidator = new AuthorValidator(RequestDbContext); var addAuthorCommandHandler = new AddAuthorCommandHandler(TestContext.CreateHandlerContext <AuthorViewModel>(RequestDbContext, CreateMapper()), _userService, authorValidator); var message = new AddAuthorCommand() { FirstName = "Tom", LastName = "Bina", About = "About me" }; await Assert.ThrowsAsync <InvalidOperationException>(async() => { await addAuthorCommandHandler.Handle(message, CancellationToken.None); }); }
public override async Task InitializeAsync() { using (var context = TestContext.CreateNewContext()) { var user = new User("Test"); var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(RequestDbContext); var author = await Author.Create(user, authorProfile, authorValidator); var blogPostContent = new BlogPostContent("Testsubject", "Testintro", "Testcontent"); var category = new Category("Testcategory", 1, "Test description"); var blogPost = new BlogPost(blogPostContent, author, category); context.BlogPosts.Add(blogPost); await context.SaveChangesAsync(); } }
static void Main(string[] args) { UserRepo userRepo = new UserRepo(); ArticleRepo articleRepo = new ArticleRepo(); AuthorRepo authorRepo = new AuthorRepo(); UserValidator userValidator = new UserValidator(); ArticleValidator articleValidator = new ArticleValidator(); AuthorValidator authorValidator = new AuthorValidator(); userRepo.SetValidator(userValidator); articleRepo.SetValidator(articleValidator); authorRepo.SetValidator(authorValidator); Manager manager = new Manager(userRepo, authorRepo, articleRepo); ConsoleUI console = new ConsoleUI(manager); console.Run(); }
public ActionResult Add(Author author) { AuthorValidator validationRules = new AuthorValidator(); ValidationResult results = validationRules.Validate(author); if (results.IsValid) { _authorService.Add(author); return(RedirectToAction("Index")); } else { foreach (var error in results.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } return(View()); } }
public override async Task InitializeAsync() { using (var context = TestContext.CreateNewContext()) { var user = new User("Test"); var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(RequestDbContext); var author = await Author.Create(user, authorProfile, authorValidator); context.Authors.Add(author); await context.SaveChangesAsync(); var userService = new Mock <IUserService>(); userService.Setup(exp => exp.GetOrCreateCurrentUserAsync()).ReturnsAsync(user); userService.Setup(exp => exp.TryGetCurrentUserAsync()).ReturnsAsync(user.ToSuccessResult()); _userService = userService.Object; _authorService = new AuthorService(_userService, RequestDbContext); } }
public override async Task InitializeAsync() { using (var context = TestContext.CreateNewContext()) { var user = new User("Test"); var authorProfile = new AuthorProfile("Tom", "Bina", "About me"); var authorValidator = new AuthorValidator(RequestDbContext); var author = await Author.Create(user, authorProfile, authorValidator); var blogPostContent = new BlogPostContent("Testsubject", "Testintro", "Testcontent"); var category = new Category("Testcategory", 1, "Test description"); var blogPost = new BlogPost(blogPostContent, author, category); context.BlogPosts.Add(blogPost); await context.SaveChangesAsync(); var userService = new Mock <IUserService>(); userService.Setup(exp => exp.GetOrCreateCurrentUserAsync()).ReturnsAsync(user); userService.Setup(exp => exp.TryGetCurrentUserAsync()).ReturnsAsync(user.ToSuccessResult()); } }
public ActionResult Index() { if (Session["User"] == null) { return(View("~/Views/Shared/Unauthorized.cshtml")); } var firstName = Request.Form["firstName"]; var lastName = Request.Form["lastName"]; var birthYear = Request.Form["birthYear"]; //Got to acces Aid var AidStr = Request.QueryString["Aid"]; var Aid = Convert.ToInt32(AidStr); //Testing with model AuthorManager DBauthor = new AuthorManager(); Author author = new Author(); author = DBauthor.getAuthor(Aid); //Validation AuthorValidator authorValidator = new AuthorValidator(); var validResult = authorValidator.validate(firstName, lastName, birthYear); if (validResult.Count == 0) { //Post to database AuthorManager editedAuthor = new AuthorManager(); editedAuthor.editAuthor(firstName, lastName, birthYear, Aid); return(View("Edited")); } else { ViewBag.Validation = validResult; return(View("authorEdit", author)); } }
public AuthorService(IAuthorRepository authorRepository) { _authorRepository = authorRepository; _authorValidator = new AuthorValidator(); }
public void Init() { this.validator = new AuthorValidator(); }
public void Setup() { authorValidator = new AuthorValidator(); }
private void SetupTestEnv() { InsertSeedRecords(); _validator = new AuthorValidator(AuthorRepository); _manager = new AuthorManager(AuthorRepository, _validator); }
public CreateAuthorViewModel(IAuthorRepository authorRepository, Author authorToEdit) { AuthorRepository = authorRepository; EditableAuthor = authorToEdit; AuthorValidator = new AuthorValidator(EditableAuthor); }
/// <summary> /// Method to validate model /// </summary> /// <returns>Returns the result of validation</returns> protected override FluentValidation.Results.ValidationResult Validate() { var validator = new AuthorValidator(); return(validator.Validate(this)); }
public AuthorController(IAuthorContainerDAL iauthorContainerDAL) { authorValidator = new AuthorValidator(); bookController = new BookController(null); authorContainer = new AuthorContainer(iauthorContainerDAL); }
public void Setup() { _validator = new AuthorValidator(); }
public void TestInitialize() { TestResult = null; authorValidator = new AuthorValidator(); }
public EditProfile() { InitializeComponent(); _authorValidator = new AuthorValidator(); }