Beispiel #1
0
        public void GetAll()
        {
            _service.Setup(r => r.GetAll()).Returns(new List <GroupBO> {
                new GroupBO()
            });

            var result = _controller.Get();

            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
        public async Task GetAllGroups_ReturnsGroups()
        {
            var group1 = new Group
            {
                Id   = 1,
                Name = "Group 1"
            };
            var group2 = new Group
            {
                Id   = 2,
                Name = "Group 2"
            };

            var service = new Mock <IGroupService>();

            service.Setup(x => x.FetchAll())
            .Returns(Task.FromResult(new List <Group> {
                group1, group2
            }))
            .Verifiable();


            var controller = new GroupsController(service.Object, Mapper.Instance);

            var result = await controller.Get() as OkObjectResult;

            List <GroupViewModel> groups = ((IEnumerable <GroupViewModel>)result.Value).ToList();

            Assert.AreEqual(2, groups.Count);
            AssertAreEqual(groups[0], group1);
            AssertAreEqual(groups[1], group2);
            service.VerifyAll();
        }
Beispiel #3
0
        public void GetGroupInfo_MultipleInvalidGroups_ShouldReturnErrorCodeAndList()
        {
            // Arrange.
            var controller = new GroupsController();

            controller.Request = HttpRequestHandler.GenerateHttpRequestMessage();
            var group    = TestConstants.InvalidGroupListMulti;
            var expected = GroupInfoResultGenerator.GenerateGroupInfoResultForMultipleInvalidGroups();

            // Act.
            var result = controller.Get(group);

            // Assert.
            Assert.IsNotNull(result);
            var groupInfoResult = result.Content.ReadAsAsync <List <GroupInfoResult> >().Result;

            Assert.IsTrue(groupInfoResult.Count > 0);
            Assert.IsTrue(expected.Count == groupInfoResult.Count);
            for (int i = 0; i < groupInfoResult.Count; i++)
            {
                Assert.IsTrue(groupInfoResult[i].code == 1);
                Assert.AreEqual(expected[i].sAMAccountName, groupInfoResult[i].sAMAccountName);
                Assert.AreEqual(expected[i].code, groupInfoResult[i].code);
                Assert.AreEqual(expected[i].displayName, groupInfoResult[i].displayName);
                Assert.AreEqual(expected[i].description, groupInfoResult[i].description);
            }
        }
Beispiel #4
0
        public async void Can_Get_Group_By_Id()
        {
            string name = Utility.RandomString();

            var model = new Model
            {
                Data = name
            };

            // create a group
            object content = await(await _groupsController.Post(model)).GetContent();

            // fetch the group using the id returned on creation
            IHttpActionResult group = await _groupsController.Get((int)content.Get("id"));

            JsonResult <UserGroupPoco> groupData = group as JsonResult <UserGroupPoco>;

            Assert.NotNull(groupData);
            Assert.Equal(name, groupData.Content.Name);
        }
        public void GroupIndex()
        {
            Mock <Storage> storage = new Mock <Storage>("name=StorageContext");

            storage.Setup(o => o.GetGroups()).Returns(groups);
            groupsController.Storage = storage.Object;

            var result = groupsController.Get() as JsonResult <JsonGroupsGetResponse>;

            Assert.AreEqual(groups.Count, result.Content.groupslist.Length);
        }
Beispiel #6
0
        public void Get_ThrowsEntityNotFoundException()
        {
            var groupServiceStub = new Mock <IGroupService>();

            groupServiceStub.Setup(x => x.GetGroups()).Throws(new EntityNotFoundException());

            var target   = new GroupsController(groupServiceStub.Object);
            var expected = target.NotFound(new EntityNotFoundException().Message);
            var actual   = target.Get() as NotFoundObjectResult;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.StatusCode, actual.StatusCode);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public void Get_WhenByQuery_ThrowsEntityNotFoundException()
        {
            var groupServiceStub = new Mock <IGroupService>();

            groupServiceStub
            .Setup(x => x.GetGroups(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <string[]>()))
            .Throws(new EntityNotFoundException());

            var target   = new GroupsController(groupServiceStub.Object);
            var expected = target.NotFound(new EntityNotFoundException().Message);
            var actual   = target.Get("name1", 1, null) as NotFoundObjectResult;

            Assert.IsNotNull(actual);
            Assert.AreEqual(expected.Value, actual.Value);
            Assert.AreEqual(expected.StatusCode, actual.StatusCode);
        }
Beispiel #10
0
        public void Get_ShouldReturnWelcomeMessage()
        {
            // Arrange.
            var controller = new GroupsController();

            controller.Request = HttpRequestHandler.GenerateHttpRequestMessage();
            var expected = "Welcome to Wind API! - GroupsController";

            // Act.
            var result = controller.Get();

            // Assert.
            Assert.IsNotNull(result);
            var getResult = result.Content.ReadAsAsync <string>().Result;

            Assert.AreEqual(expected, getResult);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        public void GetUGroupInfo_SingleInvalidGroup_ShouldReturnErrorCodeAndList()
        {
            // Arrange.
            var controller = new GroupsController();

            controller.Request = HttpRequestHandler.GenerateHttpRequestMessage();
            var expected = GroupInfoResultGenerator.GenerateGroupInfoResultForSingleInvalidGroup();

            // Act.
            var result = controller.Get(TestConstants.GroupInvalidPrime);

            // Assert.
            Assert.IsNotNull(result);
            var groupInfoResult = result.Content.ReadAsAsync <GroupInfoResult>().Result;

            Assert.IsTrue(groupInfoResult.code == 1);
            Assert.AreEqual(expected.sAMAccountName, groupInfoResult.sAMAccountName);
            Assert.AreEqual(expected.code, groupInfoResult.code);
            Assert.AreEqual(expected.displayName, groupInfoResult.displayName);
            Assert.AreEqual(expected.description, groupInfoResult.description);
        }