public IssueTagsServiceTests() { this.issueTagsList = new List <IssueTag>(); this.issueTagsRepo = new Mock <IRepository <IssueTag> >(); this.issueTagsRepo.Setup(x => x.All()).Returns(this.issueTagsList.AsQueryable()); this.issueTagsRepo.Setup(x => x.AddAsync(It.IsAny <IssueTag>())).Callback((IssueTag issueTag) => this.issueTagsList.Add(issueTag)); this.tagsList = new List <Tag>(); this.tagsRepo = new Mock <IRepository <Tag> >(); this.tagsRepo.Setup(x => x.All()).Returns(this.tagsList.AsQueryable()); this.tagsRepo.Setup(x => x.AddAsync(It.IsAny <Tag>())).Callback((Tag tag) => this.tagsList.Add(tag)); this.tagsService = new TagsService(this.tagsRepo.Object); this.issueTagsService = new IssueTagsService(this.issueTagsRepo.Object, new StringOperationsServices(), this.tagsService); }
public VotesServiceTests() { this.picturesList = new List <Picture>(); this.picturesRepo = new Mock <IDeletableEntityRepository <Picture> >(); this.picturesRepo.Setup(x => x.All()).Returns(this.picturesList.AsQueryable()); this.picturesRepo.Setup(x => x.AddAsync(It.IsAny <Picture>())).Callback((Picture picture) => this.picturesList.Add(picture)); this.picturesService = new PicturesService(this.picturesRepo.Object); this.attachmentsList = new List <Attachment>(); this.attachmentsRepo = new Mock <IDeletableEntityRepository <Attachment> >(); this.attachmentsRepo.Setup(x => x.All()).Returns(this.attachmentsList.AsQueryable()); this.attachmentsRepo.Setup(x => x.AddAsync(It.IsAny <Attachment>())).Callback((Attachment att) => this.attachmentsList.Add(att)); this.issueAttachmentsList = new List <IssueAttachment>(); this.issueAttachmentsRepo = new Mock <IRepository <IssueAttachment> >(); this.issueAttachmentsRepo.Setup(x => x.All()).Returns(this.issueAttachmentsList.AsQueryable()); this.issueAttachmentsRepo.Setup(x => x.AddAsync(It.IsAny <IssueAttachment>())).Callback((IssueAttachment issueAtt) => this.issueAttachmentsList.Add(issueAtt)); this.issuesList = new List <Issue>(); this.issuesRepo = new Mock <IDeletableEntityRepository <Issue> >(); this.issuesRepo.Setup(x => x.All()).Returns(this.issuesList.AsQueryable()); this.issuesRepo.Setup(x => x.AddAsync(It.IsAny <Issue>())).Callback((Issue issue) => this.issuesList.Add(issue)); this.issueTagsList = new List <IssueTag>(); this.issueTagsRepo = new Mock <IRepository <IssueTag> >(); this.issueTagsRepo.Setup(x => x.All()).Returns(this.issueTagsList.AsQueryable()); this.issueTagsRepo.Setup(x => x.AddAsync(It.IsAny <IssueTag>())).Callback((IssueTag issueTag) => this.issueTagsList.Add(issueTag)); this.tagsList = new List <Tag>(); this.tagsRepo = new Mock <IRepository <Tag> >(); this.tagsRepo.Setup(x => x.All()).Returns(this.tagsList.AsQueryable()); this.tagsRepo.Setup(x => x.AddAsync(It.IsAny <Tag>())).Callback((Tag tag) => this.tagsList.Add(tag)); this.tagsService = new TagsService(this.tagsRepo.Object); this.issueTagsService = new IssueTagsService(this.issueTagsRepo.Object, new StringOperationsServices(), this.tagsService); this.citizensList = new List <Citizen>(); this.citizensRepo = new Mock <IDeletableEntityRepository <Citizen> >(); this.citizensRepo.Setup(x => x.All()).Returns(this.citizensList.AsQueryable()); this.citizensRepo.Setup(x => x.AddAsync(It.IsAny <Citizen>())).Callback((Citizen citizen) => this.citizensList.Add(citizen)); this.citizensService = new CitizensService(this.citizensRepo.Object); this.addressList = new List <Address>(); this.addressesRepo = new Mock <IDeletableEntityRepository <Address> >(); this.addressesRepo.Setup(x => x.All()).Returns(this.addressList.AsQueryable()); this.addressesRepo.Setup(x => x.AddAsync(It.IsAny <Address>())).Callback((Address address) => this.addressList.Add(address)); this.addressesService = new AddressesService(this.addressesRepo.Object, this.citiesService); this.citiesList = new List <City>(); this.citiesRepo = new Mock <IRepository <City> >(); this.citiesRepo.Setup(x => x.All()).Returns(this.citiesList.AsQueryable()); this.citiesRepo.Setup(x => x.AddAsync(It.IsAny <City>())).Callback((City city) => this.citiesList.Add(city)); this.citiesService = new CitiesService(this.citiesRepo.Object); this.votesList = new List <Vote>(); this.votesRepo = new Mock <IRepository <Vote> >(); this.votesRepo.Setup(x => x.All()).Returns(this.votesList.AsQueryable()); this.votesRepo.Setup(x => x.AllAsNoTracking()).Returns(this.votesList.AsQueryable()); this.votesRepo.Setup(x => x.Delete(It.IsAny <Vote>())).Callback((Vote vote) => this.votesList.Remove(vote)); this.votesRepo.Setup(x => x.AddAsync(It.IsAny <Vote>())).Callback((Vote vote) => this.votesList.Add(vote)); this.issuesService = new IssuesService( this.issuesRepo.Object, this.issueAttachmentsRepo.Object, this.attachmentsRepo.Object, this.citizensRepo.Object, this.citizensService, this.picturesService, this.addressesService, this.issueTagsService); this.votesService = new VotesService(this.votesRepo.Object, this.citizensService, this.issuesService); }
public IssuesServiceTests() { this.mockFile = new Mock <IFormFile>(); var content = "Hello from my fake file"; var fileName = "Pic.jpg"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; this.mockFile.Setup(_ => _.OpenReadStream()).Returns(ms); this.mockFile.Setup(_ => _.FileName).Returns(fileName); this.mockFile.Setup(_ => _.Length).Returns(ms.Length); this.picturesList = new List <Picture>(); this.picturesRepo = new Mock <IDeletableEntityRepository <Picture> >(); this.picturesRepo.Setup(x => x.All()).Returns(this.picturesList.AsQueryable()); this.picturesRepo.Setup(x => x.AddAsync(It.IsAny <Picture>())).Callback((Picture picture) => this.picturesList.Add(picture)); this.picturesService = new PicturesService(this.picturesRepo.Object); this.attachmentsList = new List <Attachment>(); this.attachmentsRepo = new Mock <IDeletableEntityRepository <Attachment> >(); this.attachmentsRepo.Setup(x => x.All()).Returns(this.attachmentsList.AsQueryable()); this.attachmentsRepo.Setup(x => x.AddAsync(It.IsAny <Attachment>())).Callback((Attachment att) => this.attachmentsList.Add(att)); this.issueAttachmentsList = new List <IssueAttachment>(); this.issueAttachmentsRepo = new Mock <IRepository <IssueAttachment> >(); this.issueAttachmentsRepo.Setup(x => x.All()).Returns(this.issueAttachmentsList.AsQueryable()); this.issueAttachmentsRepo.Setup(x => x.AddAsync(It.IsAny <IssueAttachment>())).Callback((IssueAttachment issueAtt) => this.issueAttachmentsList.Add(issueAtt)); this.issuesList = new List <Issue>(); this.issuesRepo = new Mock <IDeletableEntityRepository <Issue> >(); this.issuesRepo.Setup(x => x.All()).Returns(this.issuesList.AsQueryable()); this.issuesRepo.Setup(x => x.AllAsNoTracking()).Returns(this.issuesList.AsQueryable()); this.issuesRepo.Setup(x => x.AddAsync(It.IsAny <Issue>())).Callback((Issue issue) => this.issuesList.Add(issue)); this.issueTagsList = new List <IssueTag>(); this.issueTagsRepo = new Mock <IRepository <IssueTag> >(); this.issueTagsRepo.Setup(x => x.All()).Returns(this.issueTagsList.AsQueryable()); this.issueTagsRepo.Setup(x => x.AddAsync(It.IsAny <IssueTag>())).Callback((IssueTag issueTag) => this.issueTagsList.Add(issueTag)); this.tagsList = new List <Tag>(); this.tagsRepo = new Mock <IRepository <Tag> >(); this.tagsRepo.Setup(x => x.All()).Returns(this.tagsList.AsQueryable()); this.tagsRepo.Setup(x => x.AddAsync(It.IsAny <Tag>())).Callback((Tag tag) => this.tagsList.Add(tag)); this.tagsService = new TagsService(this.tagsRepo.Object); this.issueTagsService = new IssueTagsService(this.issueTagsRepo.Object, new StringOperationsServices(), this.tagsService); this.citizensList = new List <Citizen>(); this.citizensRepo = new Mock <IDeletableEntityRepository <Citizen> >(); this.citizensRepo.Setup(x => x.All()).Returns(this.citizensList.AsQueryable()); this.citizensRepo.Setup(x => x.AllAsNoTracking()).Returns(this.citizensList.AsQueryable()); this.citizensRepo.Setup(x => x.AddAsync(It.IsAny <Citizen>())).Callback((Citizen citizen) => this.citizensList.Add(citizen)); this.citizensService = new CitizensService(this.citizensRepo.Object); this.citiesList = new List <City>(); this.citiesRepo = new Mock <IRepository <City> >(); this.citiesRepo.Setup(x => x.All()).Returns(this.citiesList.AsQueryable()); this.citiesRepo.Setup(x => x.AddAsync(It.IsAny <City>())).Callback((City city) => this.citiesList.Add(city)); this.citiesService = new CitiesService(this.citiesRepo.Object); this.addressList = new List <Address>(); this.addressesRepo = new Mock <IDeletableEntityRepository <Address> >(); this.addressesRepo.Setup(x => x.All()).Returns(this.addressList.AsQueryable()); this.addressesRepo.Setup(x => x.AddAsync(It.IsAny <Address>())).Callback((Address address) => this.addressList.Add(address)); this.addressesService = new AddressesService(this.addressesRepo.Object, this.citiesService); this.issuesService = new IssuesService( this.issuesRepo.Object, this.issueAttachmentsRepo.Object, this.attachmentsRepo.Object, this.citizensRepo.Object, this.citizensService, this.picturesService, this.addressesService, this.issueTagsService); }