public void Get()
        {
            _repo.Setup(m => m.GetAll()).Returns(GetSkills());
            var result = _controller.Get() as List <Skills>;

            Assert.Equal(3, result.Count);
        }
示例#2
0
        public void When_ItemFound_OverwritesProperties()
        {
            const string originalName   = "name";
            const string newName        = "newName";
            const int    originalRating = 10;
            const int    newRating      = 20;

            var dataStore  = new SkillsDataStore();
            var controller = new SkillsController(dataStore);

            var original = new Skill {
                Name = originalName, Rating = originalRating
            };
            var id = GetOkResultValue(controller.Post(original)).Id;

            var updated = new Skill {
                Name = newName, Rating = newRating
            };
            var result = GetOkResultValue(controller.Post(id, updated));

            // Checking properties one by one is OK as long as they are few and stable.
            // For a more complex object, I'd consider using reflection to ensure that the test
            // automatically picks up any added properties.
            Assert.Equal(newName, result.Name);
            Assert.Equal(newRating, result.Rating);

            var result2 = (Skill)((OkObjectResult)controller.Get(id)).Value;

            Assert.Equal(newName, result2.Name);
            Assert.Equal(newRating, result2.Rating);
        }
示例#3
0
文件: GetAll.cs 项目: htoomik/rater
        public void When_NoSkills_Returns_EmptyList()
        {
            var dataStore = new Mock <ISkillsDataStore>();

            dataStore.Setup(ds => ds.Get()).Returns(new List <Skill>());

            var controller = new SkillsController(dataStore.Object);

            var skills = controller.Get();

            Assert.Empty(skills);
        }
示例#4
0
        public void When_InvalidId_Returns_NotFound()
        {
            const int id = 1;

            var dataStore = new Mock <ISkillsDataStore>();

            dataStore.Setup(ds => ds.Get(id)).Throws <NotFoundException>();

            var controller = new SkillsController(dataStore.Object);

            var result = controller.Get(id);

            Assert.IsType(typeof(NotFoundResult), result);
        }
示例#5
0
        public void SkillsController_Get_ReturnsAllElementsInRepo_WhenGivenNoParameters()
        {
            var result             = controller.Get();
            var resultObjectResult = result as ObjectResult;
            var resultObject       = resultObjectResult.Value as IEnumerable <Skill>;

            Assert.IsType <ObjectResult>(result);
            Assert.Equal(3, resultObject.Count());
        }
示例#6
0
文件: GetAll.cs 项目: htoomik/rater
        public void When_HasSkills_Returns_Skills()
        {
            var dataStore = new Mock <ISkillsDataStore>();

            dataStore.Setup(ds => ds.Get()).Returns(new List <Skill> {
                new Skill()
            });

            var controller = new SkillsController(dataStore.Object);

            controller.Post(new Skill());
            var skills = controller.Get();

            Assert.Single(skills);
        }
示例#7
0
        public void When_ValidId_Returns_Item()
        {
            const int id       = 1;
            var       expected = new Skill();

            var dataStore = new Mock <ISkillsDataStore>();

            dataStore.Setup(ds => ds.Get(id)).Returns(expected);

            var controller = new SkillsController(dataStore.Object);

            var result = controller.Get(id);

            var actual = GetOkResultValue(result);

            Assert.Equal(expected, actual);
        }
示例#8
0
        public void When_ValidId_StoresItem()
        {
            var original = new Skill {
                Name = "original", Rating = 1
            };

            var dataStore  = new SkillsDataStore();
            var controller = new SkillsController(dataStore);

            var id = GetOkResultValue(controller.Post(original)).Id;

            var updated = new Skill {
                Name = "updated", Rating = 2
            };

            controller.Put(id, updated);

            var result = GetOkResultValue(controller.Get(id));

            Assert.Equal(updated.Name, result.Name);
            Assert.Equal(updated.Rating, result.Rating);
        }