public void AddWriter(WriterRegistrationInfo writerRegistrationInfo) { var writerEntity = new WriterEntity { Name = writerRegistrationInfo.Name, Surname = writerRegistrationInfo.Surname }; if (writerRepository.Contains(writerEntity)) { throw new ArgumentException("This writer has been registered. Can't continue"); } this.writerRepository.Add(writerEntity); this.writerRepository.Save(); }
public void GetWriterById_ShouldGetWriterById() { // Arrange var Id = 12; var mock = new Mock <IWriterRepository>(); var writerEntity = new WriterEntity { Id = Id }; mock.Setup(a => a.GetById(It.IsAny <int>())).Returns(writerEntity); mock.Setup(a => a.ContainsId(It.IsAny <int>())).Returns(true); var writerService = new WriterService(mock.Object); // Act var resylt = writerService.GetWriterById(Id); // Assert mock.Verify(a => a.GetById(Id)); Assert.AreEqual(resylt, writerEntity); }
public bool Contains(WriterEntity writerEntity) { return(this.dbContext.Writers.Any(a => a.Name == writerEntity.Name && a.Surname == writerEntity.Surname)); }
public void Remove(WriterEntity writerEntity) { this.dbContext.Writers.Remove(writerEntity); }
public void Add(WriterEntity writerEntity) { this.dbContext.Writers.Add(writerEntity); }