public void ItemManagerUserAccess_SettAllTagsForItem_ValidCall() { //Arrange List <Item_Tag> itemTags = new List <Item_Tag>(); List <Tag> tags = CreateTestData.GetListOfTags(); var ITmockSet = new Mock <DbSet <Item_Tag> >() .SetupData(itemTags, o => { return(itemTags.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); var tagsMockSet = new Mock <DbSet <Tag> >() .SetupData(tags, o => { return(tags.Single(x => x.Tag_id.CompareTo(o.First()) == 0)); }); //Whisper is assigned all tags! List <Tag> expected = CreateTestData.GetListOfTags(); List <Guid> tag_ids = new List <Guid>(); foreach (Tag tag in expected) { tag_ids.Add(tag.Tag_id); } Guid whisper_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0"); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.Tags).Returns(tagsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Item_Tags).Returns(ITmockSet.Object); //Act //Act IUnitOfWork UoW = mockContext.Create <UnitOfWork>(); IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW); toTest.SetAllTagsForItem(whisper_id, tag_ids); var actual = toTest.GetTagsForItem(whisper_id); //Assert actual.Should().BeEquivalentTo(expected); } }
public void ItemManagerUserAccess_SetTagForItem_ValidCall() { //Arrange List <Item_Tag> itemTags = new List <Item_Tag>(); List <Tag> tags = CreateTestData.GetListOfTags(); var ITmockSet = new Mock <DbSet <Item_Tag> >() .SetupData(itemTags, o => { return(itemTags.Single(x => x.Item_id.CompareTo(o.First()) == 0)); }); var tagsMockSet = new Mock <DbSet <Tag> >() .SetupData(tags, o => { return(tags.Single(x => x.Tag_id.CompareTo(o.First()) == 0)); }); List <Tag> expected = new List <Tag>(); Tag weapon = new Tag { Tag_id = Guid.Parse("172e8478-e1bd-49ba-a7a7-6455d5a58c6e"), TagName = "Weapon" }; expected.Add(weapon); Guid whisper_id = Guid.Parse("709135c3-6f89-46cb-80ae-4097b621e3b0"); using (var mockContext = AutoMock.GetLoose()) { mockContext.Mock <ItemsContext>() .Setup(x => x.Tags).Returns(tagsMockSet.Object); mockContext.Mock <ItemsContext>() .Setup(x => x.Item_Tags).Returns(ITmockSet.Object); //Act IUnitOfWork UoW = mockContext.Create <UnitOfWork>(); IItemsManagerUserAccess toTest = UserAccessFactory.getItemsManagerUserAccess(UoW); toTest.SetTagForItem(whisper_id, weapon.Tag_id); var actual = toTest.GetTagsForItem(whisper_id); //Assert actual.Should().BeEquivalentTo(expected); } }