Ejemplo n.º 1
0
        internal static IList <StyleClassModel> ConvertEntitiesToModels(IList <StyleClass> styleClasses)
        {
            IList <StyleClassModel> styleClassesModels = new List <StyleClassModel>();

            foreach (StyleClass styleClass in styleClasses)
            {
                styleClassesModels.Add(StyleClassModel.ToModel(styleClass));
            }
            return(styleClassesModels);
        }
 public void TestInitialize()
 {
     style                       = Utils.CreateStyleForTest();
     styleClass                  = Utils.CreateStyleClassForTest();
     styleClassModel             = StyleClassModel.ToModel(styleClass);
     mockUserAuthorizationLogic  = new Mock <IAuthorizationBusinessLogic>();
     mockStyleClassBusinessLogic = new Mock <IStyleClassBusinessLogic>();
     StyleClassController        = new StyleClassController(mockStyleClassBusinessLogic.Object, mockUserAuthorizationLogic.Object);
     InitializeToken();
 }
 public IHttpActionResult Get([FromUri] Guid id)
 {
     try
     {
         Utils.IsAValidToken(Request, AuthorizationBusinessLogic);
         Utils.HasAdminPermissions(Request, AuthorizationBusinessLogic);
         StyleClass styleClass = StyleClassBusinessLogic.Get(id);
         return(Ok(StyleClassModel.ToModel(styleClass)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public void IntegrationTest()
        {
            Guid token          = Guid.NewGuid();
            var  requestMessage = new HttpRequestMessage();

            requestMessage.Headers.Add("Token", token + "");
            mockUserAuthorizationLogic.Setup(b1 => b1.IsAValidToken(token)).Returns(true);
            mockUserAuthorizationLogic.Setup(b1 => b1.IsAdmin(token)).Returns(true);

            IStyleDataAccess         styleDA              = new StyleDataAccess();
            IStyleBusinessLogic      styleBL              = new StyleBusinessLogic(styleDA);
            IStyleClassDataAccess    styleClassDA         = new StyleClassDataAccess();
            IStyleClassBusinessLogic styleClassBL         = new StyleClassBusinessLogic(styleClassDA, styleBL);
            StyleClassController     styleClassController = new StyleClassController(styleClassBL, mockUserAuthorizationLogic.Object);

            styleClassController.Request = requestMessage;

            StyleClass      styleClassA = Utils.CreateStyleClassForTest();
            StyleClassModel styleClassM = StyleClassModel.ToModel(styleClassA);

            styleClassM.InheritedPlusProperStyles = new List <StyleModel>();
            styleClassController.Post(styleClassM);
        }
        public void integration()
        {
            var                         requestMessage = new HttpRequestMessage();
            IUserDataAccess             da             = new UserDataAccess();
            IUserBusinessLogic          userBL         = new UserBusinessLogic(new UserDataAccess());
            IAuthorizationBusinessLogic auth           = new AuthorizationBusinessLogic(da);
            IStyleDataAccess            styleDA        = new StyleDataAccess();
            IStyleBusinessLogic         styleBL        = new StyleBusinessLogic(styleDA);
            IStyleClassDataAccess       styleClassDA   = new StyleClassDataAccess();
            IStyleClassBusinessLogic    styleClassBL   = new StyleClassBusinessLogic(styleClassDA, styleBL);
            IFormatDataAccess           formatDA       = new FormatDataAccess();
            IFormatBusinessLogic        formatBL       = new FormatBusinessLogic(formatDA, styleClassBL);
            FormatController            formatC        = new FormatController(formatBL, auth);

            formatC.Request = requestMessage;
            StyleClass  styleClassA  = Utils.CreateStyleClassInDataBaseForTest();
            Format      formatA      = Utils.CreateFormatForTest();
            FormatModel formatModelA = FormatModel.ToModel(formatA);

            formatC.Post(formatModelA);
            formatC.AddStyleClassToFormat(formatA.Id, StyleClassModel.ToModel(styleClassA));
            IHttpActionResult statusObtained = formatC.Get(formatA.Id);
            int a = 2;
        }
        public void AddStyleClassToFormat_BadRequest_Exception()
        {
            mockFormatsBusinessLogic.Setup(b1 => b1.AddStyle(format.Id, styleClass)).Throws(new Exception());
            IHttpActionResult statusObtained = formatController.AddStyleClassToFormat(format.Id, StyleClassModel.ToModel(styleClass));

            Assert.IsNull(statusObtained as OkNegotiatedContentResult <string>);
        }
        public void AddStyleClassToFormat_ExpectedParameters_Ok()
        {
            mockFormatsBusinessLogic.Setup(b1 => b1.AddStyle(format.Id, styleClass));
            IHttpActionResult statusObtained = formatController.AddStyleClassToFormat(format.Id, StyleClassModel.ToModel(styleClass));

            Assert.IsNotNull(statusObtained as OkNegotiatedContentResult <string>);
        }