Exemplo n.º 1
0
        public void Get_ReturnsAllGroups()
        {
            var groupServiceStub = new Mock <IGroupService>();

            groupServiceStub.Setup(x => x.GetGroups()).Returns(_groupsToReturn);

            var target   = new GroupsController(groupServiceStub.Object);
            var expected = target.Ok("[" + string.Join(", ", _groupsToReturn.Select(x => x.ToString())) + "]");
            var actual   = target.Get() as OkObjectResult;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.StatusCode, actual.StatusCode);
        }
Exemplo n.º 2
0
        public void Get_WhenById_ReturnsGroup()
        {
            var groupServiceStub = new Mock <IGroupService>();

            groupServiceStub.Setup(x => x.GetGroupById(It.IsAny <int>()))
            .Returns(_groupsToReturn.Where(x => x.Equals(1)).FirstOrDefault);

            var target   = new GroupsController(groupServiceStub.Object);
            var expected = target.Ok(string.Join(", ", _groupsToReturn.FirstOrDefault(x => x.Equals(1))?.ToString()));
            var actual   = target.Get(1) as OkObjectResult;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.StatusCode, actual.StatusCode);
        }
Exemplo n.º 3
0
        public void Get_WhenByQuery_ReturnsGroups()
        {
            var groupServiceStub = new Mock <IGroupService>();

            groupServiceStub
            .Setup(x => x.GetGroups(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string[]>()))
            .Returns(_groupsToReturn.Where(x => x.Equals("name1", 1, null, null)));

            var target   = new GroupsController(groupServiceStub.Object);
            var expected = target.Ok("[" + string.Join(", ",
                                                       _groupsToReturn.Where(x => x.Equals("name1", 1, null, null))
                                                       .Select(x => x.ToString())) + "]");
            var actual = target.Get("name1", 1, null) as OkObjectResult;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.StatusCode, actual.StatusCode);
        }