예제 #1
0
        public void CreatePaperTest()
        {
            //Arrange
            var storedPaper = new StoredPaper {Id = 0, Type = "article"};
            _mockRepo.Setup(r => r.Create(storedPaper)).Returns(Task.FromResult(storedPaper.Id));
            var fieldTypes = new List<string>();
            fieldTypes.Add("author");
            fieldTypes.Add("title");
            fieldTypes.Add("year");
            var fieldValues = new List<string>();
            fieldValues.Add("Will BeGood");
            fieldValues.Add("Life's Questions");
            fieldValues.Add("1905");

            var paper = new Paper("article", fieldTypes, fieldValues);

            //Act
            var paperId = _adapter.Create(paper);

            //Assert
            Assert.IsTrue(paperId.Result == 0);
        }
예제 #2
0
        public async Task DeleteObjectCorrectStateTest()
        {
            //Arrange
            var fieldTypes = new List<string>();
            fieldTypes.Add("author");
            fieldTypes.Add("title");
            fieldTypes.Add("year");
            var fieldValues = new List<string>();
            fieldValues.Add("Will BeGood");
            fieldValues.Add("Life's Questions");
            fieldValues.Add("1905");
            var paper = new Paper("article", fieldTypes, fieldValues);

            StoredPaper callBackPaper = null;
            _mockRepo.Setup(r => r.DeleteIfExists(It.IsAny<StoredPaper>().Id)).Callback<StoredPaper>(o => callBackPaper = o);

            //Act
            await _adapter.DeleteIfExists(0);

            //Assert
            //TODO Make NUnit TestCase() work and reduce method to a single Assert
            Assert.IsTrue(callBackPaper.Id == 0);
            Assert.IsTrue(callBackPaper.Type == "article");
            Assert.IsTrue(callBackPaper.FieldTypes.Count == 3);
            Assert.IsTrue(callBackPaper.FieldValues.Count == 3);
            Assert.IsTrue(callBackPaper.FieldTypes.ElementAt(0) == "author");
            Assert.IsTrue(callBackPaper.FieldTypes.ElementAt(1) == "title");
            Assert.IsTrue(callBackPaper.FieldTypes.ElementAt(2) == "year");
            Assert.IsTrue(callBackPaper.FieldValues.ElementAt(0) == "Will BeGood");
            Assert.IsTrue(callBackPaper.FieldValues.ElementAt(1) == "Life's Questions");
            Assert.IsTrue(callBackPaper.FieldValues.ElementAt(2) == "1905");
        }
예제 #3
0
        public void ReadAllObjectsTypeTest()
        {
            //Arrange
            var fieldTypes = new List<string>();
            fieldTypes.Add("author");
            fieldTypes.Add("title");
            fieldTypes.Add("year");
            var fieldValues = new List<string>();
            fieldValues.Add("Will BeGood");
            fieldValues.Add("Life's Questions");
            fieldValues.Add("1905");
            var paper1 = new Paper("article", fieldTypes, fieldValues);
            var paper2 = new Paper("phdthesis", fieldTypes, fieldValues);
            var paper3 = new Paper("book", fieldTypes, fieldValues);
            var paper4 = new Paper("notebook", fieldTypes, fieldValues);
            var paper5 = new Paper("ebook", fieldTypes, fieldValues);

            var paperCollection = new List<StoredPaper>();
            paperCollection.Add(Mapper.Map<StoredPaper>(paper1));
            paperCollection.Add(Mapper.Map<StoredPaper>(paper2));
            paperCollection.Add(Mapper.Map<StoredPaper>(paper3));
            paperCollection.Add(Mapper.Map<StoredPaper>(paper4));
            paperCollection.Add(Mapper.Map<StoredPaper>(paper5));

            _mockRepo.Setup(r => r.Read()).Returns(paperCollection.AsQueryable());

            //Act
            var papers = _adapter.Read();

            //Assert
            for (var i = 0; i < papers.Count(); i++)
            {
                Assert.IsTrue(papers.ElementAt(i).Type == paperCollection.ElementAt(i).Type);
            }
        }
예제 #4
0
        public async Task UpdateObjectNotNullTest()
        {
            //Arrange
            var fieldTypes = new List<string>();
            fieldTypes.Add("author");
            fieldTypes.Add("title");
            fieldTypes.Add("year");
            var fieldValues = new List<string>();
            fieldValues.Add("Will BeGood");
            fieldValues.Add("Life's Questions");
            fieldValues.Add("1905");
            var paper = new Paper("article", fieldTypes, fieldValues);

            StoredPaper callBackPaper = null;
            _mockRepo.Setup(r => r.UpdateIfExists(It.IsAny<StoredPaper>())).Callback<StoredPaper>(o => callBackPaper = o);

            //Act
            await _adapter.UpdateIfExists(paper);

            //Assert
            Assert.IsNotNull(callBackPaper);
        }
예제 #5
0
        private static List<Paper> CreateReports()
        {
            var fieldTypes = new ReadOnlyCollection<string>(new List<string>
            {
                "author",
                "title",
                "year"
            });
            var fieldValues = new ReadOnlyCollection<string>(new List<string>
            {
                "Sam",
                "Sam Learns to Program",
                "2015"
            });

            var paper1 = new Paper("book", fieldTypes, fieldValues) { ResourceRef = "1" };
            var paper2 = new Paper("book", fieldTypes, fieldValues) { ResourceRef = "2" };
            var paper3 = new Paper("book", fieldTypes, fieldValues) { ResourceRef = "3" };

            return new List<Paper> { paper1, paper2, paper3 };
        }