示例#1
0
        public void PostWithValidObject()
        {
            _service.Setup(r => r.Create(It.IsAny <GroupBO>())).Returns(new GroupBO());

            var result = _controller.Post(new GroupBO {
                Id = 1, ContactEmail = "Test", Students = new List <StudentBO>()
            });

            Assert.IsType <OkObjectResult>(result);
        }
示例#2
0
        public void PostGroup_CorrectGroup_ReturnsOk()
        {
            var fakeGroup = new Group
            {
                Name     = "MyGroup",
                Category = GroupCategory.Friends,
                Users    = new List <User>()
                {
                    new User {
                        Username = "******"
                    }
                },
                CurrentBalance = 0
            };

            var fakeSaveResult = new SaveResultModel <Group>
            {
                Model   = fakeGroup,
                Success = true
            };

            var groupServiceMock = new Mock <IGroupService>();

            groupServiceMock.Setup(m => m.CreateGroup(It.IsAny <Group>())).Returns(fakeSaveResult);
            controller = new GroupsController(groupServiceMock.Object, null);

            var result = controller.Post(fakeGroup);

            Assert.IsTrue(result != null);
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <Group>));
        }
        public async Task CreateGroup_ReturnsCreatedGroup()
        {
            var group = new GroupInputViewModel
            {
                Name = "Group"
            };
            var service = new Mock <IGroupService>();

            service.Setup(x => x.AddGroup(It.Is <Group>(g => g.Name == group.Name)))
            .Returns(Task.FromResult(new Group
            {
                Id   = 2,
                Name = group.Name
            }))
            .Verifiable();

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

            var result = await controller.Post(group) as CreatedAtActionResult;

            var resultValue = result.Value as GroupViewModel;

            Assert.IsNotNull(resultValue);
            Assert.AreEqual(2, resultValue.Id);
            Assert.AreEqual("Group", resultValue.Name);
            service.VerifyAll();
        }
        public async Task CreateGroup_RequiresGroup()
        {
            var service    = new Mock <IGroupService>(MockBehavior.Strict);
            var controller = new GroupsController(service.Object, Mapper.Instance);


            var result = await controller.Post(null) as BadRequestResult;

            Assert.IsNotNull(result);
        }
        public void CreateGroupCtrl()
        {
            Mock <Storage> storage  = new Mock <Storage>("name=StorageContext");
            Groups         newgroup = new Groups
            {
                IDGroup = 1,
                Name    = "Nowa"
            };

            storage.Setup(o => o.GetGroups()).Returns(groups);
            List <Groups> tmpGroups = new List <Groups>();

            tmpGroups.Add(groups.First());
            storage.Setup(o => o.GetGroups("A")).Returns(tmpGroups);

            storage.Setup(o => o.CreateGroup(newgroup.Name)).Callback(() => groups.Add(newgroup));
            groupsController.Storage = storage.Object;

            var result = groupsController.Post(newgroup, "POST") as JsonResult <JsonGroupsGetResponse>;


            Assert.AreEqual(6, groups.Count);
            Assert.AreEqual(groups.Count, result.Content.groupslist.Length);
        }
示例#6
0
        public void PostGroup_NullGroup_ReturnsBadRequest()
        {
            var fakeSaveResult = new SaveResultModel <Group>
            {
                Model   = null,
                Success = false
            };

            var groupServiceMock = new Mock <IGroupService>();

            groupServiceMock.Setup(m => m.CreateGroup(It.IsAny <Group>())).Returns(fakeSaveResult);
            controller = new GroupsController(groupServiceMock.Object, null);

            var result = controller.Post(null);

            Assert.IsTrue(result != null);
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
示例#7
0
        public async void Can_Create_Group()
        {
            string name = Utility.RandomString();

            var model = new Model
            {
                Data = name
            };

            object content = await(await _groupsController.Post(model)).GetContent();

            Assert.Equal(200, (int)content.Get("status"));
            Assert.Equal(MagicStrings.GroupCreated.Replace("{name}", name), content.Get("msg"));
        }