Exemple #1
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);
            }
        }
            public async Task Index_ReturnsAViewResult_WithData()
            {
                // Arrange
                var gr = new List <Group>()
                {
                    new Group
                    {
                        Id   = 1,
                        Name = "AMI31"
                    }
                };
                var mockLogic = new Mock <IGroupsLogic>();

                mockLogic.Setup(repo => repo.GetGroups()).Returns(Task.FromResult(gr));
                var controller = new GroupsController(mockLogic.Object);

                // Act
                var result = await controller.Index();

                // Assert
                var viewResult = Assert.IsType <ViewResult>(result);
                var model      = Assert.IsAssignableFrom <List <Group> >(
                    viewResult.ViewData.Model);

                Assert.Equal(gr[0].Name, model[0].Name);
            }
Exemple #3
0
        public async Task CreateGroupController_GroupNotExist_ReturnsConflict()
        {
            // Arrange
            var controller = new GroupsController(new GroupRepositoryStub(), new UserRepositoryStub(),
                                                  new SmartLockRepositoryStub(), new AzureAdRepositoryStub(), _mapper);

            var groupCreationDto = new GroupCreationDto
            {
                Id              = Guid.Parse("c374cb18-862e-4fef-871f-ae08337d1f76"),
                Status          = Status.Active,
                SmartLockGroups = new List <SmartLockCollectionDto>
                {
                    new SmartLockCollectionDto
                    {
                        SmartLockId = Guid.Parse("3fa85f64-5717-4562-b3fc-2c963f66afa6")
                    }
                }
            };

            // Act
            var result = await controller.CreateGroup(groupCreationDto);

            // Assert
            Assert.IsInstanceOfType(result.Result, typeof(ConflictObjectResult));
        }
Exemple #4
0
        [InlineData("453a2901-150b-4211-84b1-a40ac2ba4a35", 15, -1, false)] // Unsuccessful Kick (no such group)
        public void TestKickFromGroup(string creatorAspId, int targetUserId, int groupId, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => creatorAspId
            };

            var result = controller.Kick(targetUserId, groupId);

            if (expectingSuccess)
            {
                Assert.True(result is RedirectToRouteResult);
                var redirectResult = (RedirectToRouteResult)result;
                Assert.Equal("Details", redirectResult.RouteValues["action"]);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Exemple #5
0
        public void PutExpense_CorrectExpense_ReturnOk()
        {
            var fakeExpense = new Expense
            {
                Description   = "tmp",
                Type          = ExpenseType.Entertainment,
                Date          = DateTime.Now,
                Currency      = Currency.CAD,
                IsTaxIncluded = true,
                CurrentAmount = 1,
                InitialAmount = 1,
                Payer         = new User()
            };

            var fakeSaveResult = new SaveResultModel <Expense>
            {
                Model   = fakeExpense,
                Success = true
            };

            var expenseServiceMock = new Mock <IExpenseService>();
            var groupServiceMock   = new Mock <IGroupService>();

            groupServiceMock.Setup(m => m.GetGroup(It.IsAny <int>())).Returns(new Group());
            expenseServiceMock.Setup(m => m.UpdateExpense(It.IsAny <Expense>())).Returns(fakeSaveResult);
            controller = new GroupsController(groupServiceMock.Object, expenseServiceMock.Object);

            var result = controller.PutExpense(10, 5, new Expense());

            Assert.IsTrue(result != null);
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <Expense>));
        }
        public void SetUp()
        {
            SetupTestInfrastructureAsync(services => services.AddScoped <GroupsController>()).GetAwaiter().GetResult();

            groupsController = GetController <GroupsController>();
            groupsRepo       = serviceProvider.GetService <IGroupsRepo>();
        }
        public async Task GetGroupsByCountry_ShouldReturnStatusOkAndIEnumerableOfGroupDto()
        {
            //Arrange
            var groupServiceMock = Substitute.For <IGroupService>();
            var group            = new Group {
                Id = 1, Name = "someName", Country = "someCountry", CreationYear = 2000
            };
            var expected = new List <GroupDto> {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            };

            groupServiceMock.GetAllAsync().Returns(new List <GroupDto>
            {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            });
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetGroupsByCountry("someCountry");

            //Assert
            await groupServiceMock.Received().FindOneAsync(g => g.Country == "someCountry");

            //Assert.Equal(200, ((StatusCodeResult) response.Result).StatusCode);
            //Assert.Equal(expected, response.Value);
        }
        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();
        }
Exemple #9
0
        public GroupControllerTest()
        {
            _filteredUrl = new Mock <IFilteredUrl>();
            _logger      = new Mock <ILogger <GroupsController> >();

            var emailLogger      = new Mock <ILogger <GroupEmailBuilder> >();
            var eventEmailLogger = new Mock <ILogger <EventEmailBuilder> >();
            var emailClient      = new Mock <IHttpEmailClient>();
            var emailConfig      = new Mock <IApplicationConfiguration>();

            emailConfig.Setup(a => a.GetEmailEmailFrom(It.IsAny <string>()))
            .Returns(AppSetting.GetAppSetting("GroupSubmissionEmail"));

            _groupEmailBuilder = new Mock <GroupEmailBuilder>(emailLogger.Object, emailClient.Object, emailConfig.Object, new BusinessId("BusinessId"));
            _eventEmailBuilder = new Mock <EventEmailBuilder>(eventEmailLogger.Object, emailClient.Object, emailConfig.Object, new BusinessId("BusinessId"));

            var mockTime   = new Mock <ITimeProvider>();
            var viewHelper = new ViewHelpers(mockTime.Object);

            datetimeCalculator = new DateCalculator(mockTime.Object);

            http = new Mock <IHttpContextAccessor>();

            var cookies = new FakeCookie(true);

            http.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies);

            _groupController = new GroupsController(_processedRepository.Object, _repository.Object, _groupEmailBuilder.Object, _eventEmailBuilder.Object, _filteredUrl.Object, _logger.Object, _configuration.Object, _markdownWrapper.Object, viewHelper, datetimeCalculator, _loggedInHelper.Object, _groupsService.Object, _cookiesHelper.Object, new StockportWebapp.FeatureToggling.FeatureToggles());

            // setup mocks
            _groupsService.Setup(o => o.GetGroupCategories()).ReturnsAsync(groupCategories);
            _groupsService.Setup(o => o.GetGroupHomepage()).ReturnsAsync(groupHomepage);
            _groupsService.Setup(o => o.GetAvailableGroupCategories()).ReturnsAsync(new List <string>());
            _groupsService.Setup(o => o.GetErrorsFromModelState(It.IsAny <ModelStateDictionary>())).Returns("");
        }
Exemple #10
0
 public GroupsControllerTests()
 {
     _service = new Mock <IGroupService>();
     _service.Setup(x => x.GetAllAsync()).ReturnsAsync(GetTestGroups());
     _service.Setup(x => x.GetAllAsync()).ReturnsAsync(GetTestGroups());
     _controller = new GroupsController(_service.Object);
 }
Exemple #11
0
        [InlineData("453a2901-150b-4211-84b1-a40ac2ba4a35", -1, false, false, false, false)] // Unsuccessful Details (Group does not exist)
        public void TestGroupDetails(string userAspId, int groupId, bool expectingSuccess, bool isClosed, bool isCreator, bool isRegularMember)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => userAspId
            };

            var result = controller.Details(groupId);

            if (expectingSuccess)
            {
                if (isClosed)
                {
                    Assert.True(result is RedirectToRouteResult);
                    var redirectResult = (RedirectToRouteResult)result;
                    Assert.Equal("ClosedDetails", redirectResult.RouteValues["action"]);
                    Assert.Equal(groupId, redirectResult.RouteValues["groupId"]);
                }

                else if (isCreator)
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("CreatorDetails", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }

                else if (isRegularMember)
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("MemberDetails", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }

                else
                {
                    Assert.True(result is ViewResult);
                    var viewResult = (ViewResult)result;
                    Assert.Equal("", viewResult.ViewName);
                    Assert.Equal(groupId, ((GroupDetailsViewModel)viewResult.Model).Group.GroupId);
                }
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Exemple #12
0
        [InlineData("453a2901-150b-4211-84b1-a40ac2ba4a3", 19, false)] // Unsuccessful Rate (Group is not closed)
        public void TestRate(string userAspId, int groupId, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => userAspId
            };

            var result = controller.Rate(groupId);

            if (expectingSuccess)
            {
                Assert.True(result is ViewResult);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
Exemple #13
0
        [InlineData(19, "453a2901-150b-4211-84b1-a40ac2ba4a35", true, false)]  // Unsuccessful Join (User already in group)
        public void TestJoinGroup(int groupId, string aspUserId, bool userIsSecLevel1, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            controllerContextMock.Setup(c => c.HttpContext.User.IsInRole("SecurityLevel1")).Returns(userIsSecLevel1);

            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => aspUserId
            };
            var result = controller.Join(groupId);

            if (expectingSuccess)
            {
                var redirectResult = (RedirectToRouteResult)result;
                Assert.Equal("Details", redirectResult.RouteValues["action"]);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult || result is ContentResult);
            }
        }
Exemple #14
0
        [InlineData("881bf243-d34d-49cb-b22b-cc3cd7a0fac5", 19, false, false)] // Unsuccessful Leave (User does not have security level 1)
        public void TestLeaveGroup(string userAspId, int groupId, bool userIsSecLevel1, bool expectingSuccess)
        {
            var controllerContextMock = new Mock <ControllerContext>()
            {
                CallBase = true
            };
            var contextMock = new Mock <ApplicationDbContext>()
            {
                CallBase = true
            };

            contextMock.Setup(c => c.SaveChanges()).Returns(1);
            controllerContextMock.Setup(c => c.HttpContext.User.IsInRole("SecurityLevel1")).Returns(userIsSecLevel1);
            var controller = new GroupsController
            {
                ControllerContext = controllerContextMock.Object,
                Context           = contextMock.Object,
                GetUserId         = () => userAspId
            };

            var result = controller.Leave(groupId);

            if (expectingSuccess)
            {
                Assert.True(result is RedirectToRouteResult);
            }
            else
            {
                Assert.True(result is HttpNotFoundResult);
            }
        }
        public async Task GetAllGroupsAsync_ShouldReturnStatusOkAndListOfGroups()
        {
            //Arrange
            var groupRepoMock = Substitute.For <IGroupRepository>();

            groupRepoMock.GetAllAsync().Returns(new List <Group>
            {
                new Group {
                    Id = 1, Name = "someName", Country = "someCountry", CreationYear = 2000
                }
            });
            var groupServiceMock = Substitute.For <IGroupService>();
            var expected         = new List <GroupDto> {
                GroupDto.GetGroupDtoWithId(1, "someName", "someCountry", 2000)
            };

            groupServiceMock.GetAllAsync().Returns(expected);
            var sut = new GroupsController(groupServiceMock);

            //Act
            var response = await sut.GetAllGroupsAsync();

            //Assert
            await groupServiceMock.Received().GetAllAsync();

            //Assert.Equal(200, ((StatusCodeResult)response).StatusCode)); //need to fix(can`t get statusCode & value from ActionResult) but result is correct
            //Assert.Equal(expected, response.Value);
        }
        public void TestIndexAction_ShouldReturnDefaultView()
        {
            var data       = new LinkedInData(new LinkedInContext());
            var controller = new GroupsController(data, new MemoryCacheService(data));

            controller.WithCallTo(x => x.Index()).ShouldRenderDefaultView();
        }
    void Start()
    {
        _groupsController = FindObjectOfType <GroupsController>();
        _itemsController  = FindObjectOfType <ItemsController>();
        _extraController  = FindObjectOfType <ExtraController>();
        _itemsTabControl  = FindObjectOfType <ItemsTabControl>();

        CartModel = new CartModel();

        ItemIcons = new Dictionary <string, Sprite>();

        if (FindObjectOfType <XsollaLogin>() != null)
        {
            print("Store demo starts. Use token obtained from Login: "******"Store demo starts. Use default hardcoded token: " + DefaultStoreToken);
            XsollaStore.Instance.Token = DefaultStoreToken;
        }

        XsollaStore.Instance.CreateNewCart(XsollaSettings.StoreProjectId, newCart => { Cart = newCart; }, ShowError);

        XsollaStore.Instance.GetListOfItems(XsollaSettings.StoreProjectId, InitStoreUi, ShowError);

        RefreshInventory();
    }
        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();
        }
Exemple #19
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>));
        }
Exemple #20
0
        public void PutExpense_NullExpense_ReturnBadRequest()
        {
            controller = new GroupsController(null, null);
            var result = controller.PutExpense(10, 5, null);

            Assert.IsTrue(result != null);
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
        public async Task DeleteGroup_RequiresPositiveId(int groupId)
        {
            var service    = new Mock <IGroupService>(MockBehavior.Strict);
            var controller = new GroupsController(service.Object, Mapper.Instance);

            var result = await controller.Delete(groupId);

            Assert.IsTrue(result is BadRequestObjectResult);
        }
Exemple #22
0
        public async Task CreateGroup_RequiresGroup()
        {
            var service    = new Mock <IGroupService>(MockBehavior.Strict);
            var controller = new GroupsController(service.Object, Mapper.Instance);

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

            Assert.IsNotNull(result);
        }
Exemple #23
0
    protected virtual void Start()
    {
        _groupsController = FindObjectOfType <GroupsController>();
        _itemsController  = FindObjectOfType <ItemsController>();
        _itemsTabControl  = FindObjectOfType <ItemsTabControl>();

        ApplyStoreImplementation(GetImplementation());
        CatalogInit();
    }
Exemple #24
0
        public async Task GetAllGroupsAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _groupDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception());
            var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetAllGroupsAsync();

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Exemple #25
0
        public void GetAllGroups_ShouldReturnAllGroups()
        {
            var testGroup  = GetTestGroup();
            var controller = new GroupsController(testGroup);

            var result = controller.GetGroups() as DbQuery <Group>;

            Assert.AreEqual(testGroup.Count, result.Count());
        }
Exemple #26
0
        public void Init()
        {
            #region Dummy Activity && ActivitySchedules Lists
            activities = new List <Activity>
            {
                new Activity {
                    ActivityID = 1, Name = "Gimnasio", Description = "Gimnasio, pesas, bicicletas, máquinas para correr"
                },
                new Activity {
                    ActivityID = 2, Name = "Pilates", Description = "Sistema de entrenamiento físico y mental"
                },
                new Activity {
                    ActivityID = 3, Name = "Boxeo", Description = "Deporte de combate"
                }
            };


            /* activitySchedules = new List<Group>
             * {
             *   new Group { ActivityScheduleID = 1, ActivityID = 1, Day = "Lunes a Viernes", HourFrom = 08, HourTo = 22, Activity = activities.ElementAt(0)},
             *   new Group { ActivityScheduleID = 2, ActivityID = 2, Day = "Lunes", HourFrom = 11, HourTo = 12, Activity = activities.ElementAt(1)},
             *   new Group { ActivityScheduleID = 3, ActivityID = 2, Day = "Lunes", HourFrom = 16, HourTo = 17, Activity = activities.ElementAt(1)},
             *   new Group { ActivityScheduleID = 4, ActivityID = 2, Day = "Miércoles", HourFrom = 19, HourTo = 21, Activity = activities.ElementAt(2)},
             *   new Group { ActivityScheduleID = 5, ActivityID = 3, Day = "Miércoles", HourFrom = 9, HourTo = 10, Activity = activities.ElementAt(2)},
             *   new Group { ActivityScheduleID = 6, ActivityID = 3, Day = "Miércoles", HourFrom = 20, HourTo = 21, Activity = activities.ElementAt(1)},
             * };
             */
            #endregion

            #region Dummy New Activity
            newActivitySchedule = new Group {
                ActivityID = 1, Day = "Lunes y Jueves", HourFrom = 16, HourTo = 18
            };
            #endregion

            #region Repositories
            activitySchedulesRepository = Mock.Create <IGroupRepository>();
            activityRepository          = Mock.Create <IActivityRepository>();
            #endregion

            #region JustMock GetActivities Arrange
            Mock.Arrange(() => activitySchedulesRepository.GetActivitySchedules()).Returns(activitySchedules);
            Mock.Arrange(() => activitySchedulesRepository.GetActivityScheduleByID(ACTIVITY_SCHEDULE_ID_TO_USE))
            .Returns(activitySchedules.Where(a => a.ActivityID == ACTIVITY_SCHEDULE_ID_TO_USE).FirstOrDefault());
            Mock.Arrange(() => activitySchedulesRepository.InsertActivitySchedule(newActivitySchedule))
            .DoInstead(() => activitySchedules.Add(newActivitySchedule))
            .MustBeCalled();
            Mock.Arrange(() => activitySchedulesRepository.DeleteActivitySchedule(ACTIVITY_SCHEDULE_ID_TO_USE))
            .DoInstead(() => activitySchedules.Remove(activitySchedules.Where(a => a.ActivityScheduleID == ACTIVITY_SCHEDULE_ID_TO_USE).FirstOrDefault()));
            Mock.Arrange(() => activitySchedulesRepository.Save()).DoNothing();
            #endregion

            #region Controller creation
            controller = new GroupsController(activitySchedulesRepository, activityRepository);
            #endregion
        }
Exemple #27
0
        public async Task GetGroupAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException()
        {
            // Example of these errors: database does not exist, table does not exist etc.
            _groupDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetGroupAsync("1");

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
Exemple #28
0
        public async Task GetGroupAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            _groupDbServiceMock.Setup(x => x.GetAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetGroupAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError());
        }
Exemple #29
0
        public async Task GetGroupAsync__Element_not_found__Should_return_404NotFound_response()
        {
            _groupDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException());
            var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetGroupAsync("1");

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError());
        }
Exemple #30
0
        public async Task GetAvailableGroupDatesAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _groupDbServiceMock.Setup(x => x.GetByAsync(It.IsAny <Expression <Func <SightseeingGroup, bool> > >())).ThrowsAsync(new Exception());
            _infoDbServiceMock.Setup(x => x.GetAllAsync()).ThrowsAsync(new Exception());
            var controller = new GroupsController(_dbServiceFactoryMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetAvailableGroupDatesAsync();

            await result.Should().ThrowExactlyAsync <Exception>();
        }