Esempio n. 1
0
        public void DealLockManager_ShouldCall_UnlockDeal(int dealNumber, bool isLocked)
        {
            #region Arrange

            Mock <IEntityLockRepository> dealLockRepository = new Mock <IEntityLockRepository>();
            SetupUserIdentity();
            SetupDealLockRepository(dealLockRepository, dealNumber, userIdentity.UserId, isLocked);

            string url         = $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}{RouteHelper.DealLocksPrefix}";
            var    httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), url);

            DealLocksController dealLocksController = CreateDealLocksController(httpRequest, dealLockRepository.Object);

            #endregion

            #region Act
            var response = dealLocksController.Unlock(dealNumber);
            var result   = response as StatusCodeResult;
            //var contentResult = response as OkNegotiatedContentResult<ResponseItem<EntityLock>>;

            #endregion

            #region Assert
            HttpStatusCode expectedStatusCode = isLocked ? HttpStatusCode.ExpectationFailed : HttpStatusCode.OK;
            Assert.AreEqual(expectedStatusCode, result.StatusCode);
            #endregion
        }
Esempio n. 2
0
        private DealLocksController CreateDealLocksController(HttpRequestMessage httpRequest, IEntityLockRepository dealLockRepository)
        {
            EntityLockManager dealLockManager = new EntityLockManager(userManager.Object, cacheStoreManager, mockLogManager.Object, dealLockRepository, transformationManager);
            DealManager       dealManager     = new DealManager(userManager.Object, cacheStoreManager, mockLogManager.Object,
                                                                new Mock <IDealRepository>().Object, new Mock <IWorkbenchDealsRepository>().Object, new Mock <ITblDealRepository>().Object,
                                                                new Mock <IDealStatusesLookupManager>().Object, dealLockManager, new Mock <IDealTransformationManager>().Object,
                                                                new Mock <ICedantManager>().Object, new Mock <IBrokerManager>().Object, new Mock <ITblClausesDealRepository>().Object);

            DealAPIManager dealAPIManager = new DealAPIManager(userManager.Object, cacheStoreManager, mockLogManager.Object, dealManager, dealLockManager);

            DealLocksController dealLocksController = new DealLocksController(userManager.Object, dealAPIManager)
            {
                Request       = httpRequest,
                Configuration = new HttpConfiguration()
            };

            return(dealLocksController);
        }
Esempio n. 3
0
        public void DealLockManager_ShouldCall_LockDeal_Throws_NotAllowedAPIException(int dealNumber, bool isLocked, bool isNegative)
        {
            #region Arrange

            Mock <IEntityLockRepository> dealLockRepository = new Mock <IEntityLockRepository>();
            SetupUserIdentity();
            SetupDealLockRepository(dealLockRepository, dealNumber, userIdentity.UserId, isLocked, isNegative);

            string url         = $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}{RouteHelper.DealLocksPrefix}";
            var    httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), url);

            DealLocksController dealLocksController = CreateDealLocksController(httpRequest, dealLockRepository.Object);

            #endregion

            #region Assert
            Assert.Throws(typeof(NotAllowedAPIException), delegate { dealLocksController.Lock(dealNumber); });
            #endregion
        }
Esempio n. 4
0
        public void DealLocksController_GetLocks_Returns_OKResponseCode(int dealNumber, bool isLocked)
        {
            #region Arrange

            Mock <IEntityLockRepository> dealLockRepository = new Mock <IEntityLockRepository>();
            SetupUserIdentity();
            SetupDealLockRepository(dealLockRepository, dealNumber, userIdentity.UserId, isLocked);

            string url = $"{AppSettings.BASEURL}{ RouteHelper.DealsRoutePrefix }/{dealNumber}/locks";
            //string url = $"{AppSettings.BASEURL}{RouteHelper.DealsRoutePrefix}{RouteHelper.DealLocksPrefix}";
            var httpRequest = new HttpRequestMessage(new HttpMethod(AppSettings.HTTPGET), url);

            DealLocksController dealLocksController = CreateDealLocksController(httpRequest, dealLockRepository.Object);

            #endregion

            #region Act

            var response      = dealLocksController.GetLocks(dealNumber);
            var contentResult = response as NegotiatedContentResult <ResponseItem <EntityLock> >;

            #endregion

            #region Assert

            #region Expected Data

            var expectedDealLock = new  EntityLock()
            {
                entityId            = dealNumber,
                entityTypeName      = EntityType.Deals.ToString(),
                lockedByDisplayName = "John Doe",
                lockedTimestamp     = DateTime.MinValue
            };

            string  expectedURL      = ($"/{ RouteHelper.DealsRoutePrefix }/{dealNumber }/locks");
            var     expectedMessages = new List <Message>();
            Message expectedMessage  = new Warning("entityID", $"{ expectedDealLock.lockedByDisplayName} has locked this deal for edit");
            expectedMessages.Add(expectedMessage);
            IList <Link> links = null;
            ResponseItem <EntityLock> expectedContent = new ResponseItem <EntityLock>(expectedURL, expectedDealLock, links, expectedMessages);

            #endregion

            Assertions.AssertOkResponse(contentResult);

            var actualDealLock = contentResult.Content.data;
            if (isLocked)
            {
                Assertions.AreEqualByJson(expectedContent, contentResult.Content);
            }
            else
            {
                Assert.IsNull(actualDealLock);
                Assert.IsNull(contentResult.Content.messages);
                Assert.IsNull(links);
            }



            #endregion
        }