Exemple #1
0
 private static Measure ParseFailure(IDataConverter converter)
 {
     return(Measure.Create("failure")
            .ReferenceAction(() =>
     {
         try
         {
             var _ = Convert.ToInt32("X");
         }
         catch { }
     })
            .MeasurementAction(() => converter.Convert("X").To <int>()));
 }
        public void CoreApiExceptionToCoreApiExceptionModel()
        {
            // Arrange
            var coreApiException = new CoreApiException(HttpStatusCode.NotFound, "The thing was not found");

            // Act
            var coreApiExceptionModel = _dataConverter.Convert <CoreApiExceptionModel>(coreApiException);

            // Assert
            Check.That(coreApiExceptionModel).IsInstanceOf <CoreApiExceptionModel>();
            Check.That(coreApiExceptionModel.DateTime).IsEqualTo(coreApiException.DateTime);
            Check.That(coreApiExceptionModel.StatusCode).IsEqualTo(coreApiException.StatusCode);
            Check.That(coreApiExceptionModel.Message).IsEqualTo(coreApiException.Message);
        }
Exemple #3
0
        public void Execute(IActor actor)
        {
            if (actor == null)
            {
                throw new ArgumentNullException(nameof(actor));
            }

            var result = _converter.Convert(_data, _type);

            if (result == null)
            {
                throw new ExpectationException($"Failed to convert data into artifact of type {_type}. Text to convert: {_data}.");
            }

            actor.Artifacts.Add(result);
        }
        //internal string RetrieveSubjectManageUrlFormatString(object subjectId)
        //{
        //    ArgumentValidator.IsNotNull("subjectId", subjectId);
        //    ISubjectService service = UnitOfWork.GetService<ISubjectService>();
        //    var query = service.Retrieve(subjectId);
        //    if (query.HasResult)
        //    {
        //        return query.Data.ManageUrl;
        //    }
        //    return null;
        //}

        //internal string RetrieveSubjectType(object subjectId)
        //{
        //    ArgumentValidator.IsNotNull("subjectId", subjectId);
        //    ISubjectService service = UnitOfWork.GetService<ISubjectService>();
        //    var query = service.Retrieve(subjectId);
        //    if (query.HasResult)
        //    {
        //        return query.Data.SubjectType;
        //    }
        //    return null;
        //}

        internal IEnumerable <SubjectFieldInfoDto> RetrieveSubjectFieldInfos(object subjectId, IDataConverter <SubjectFieldInfoData, SubjectFieldInfoDto> converter)
        {
            ArgumentValidator.IsNotNull("subjectId", subjectId);
            ArgumentValidator.IsNotNull("converter", converter);

            ISubjectService service = UnitOfWork.GetService <ISubjectService>();

            IEnumerable <SubjectFieldInfoData> result = service.GetSubjectFieldInfosData(subjectId);

            if (result != null)
            {
                return(converter.Convert(result));
            }

            return(null);
        }
        internal TDto RetrieveOrNewReview <TDto>(object instanceId, IDataConverter <ReviewData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("converter", converter);
            IReviewService service = UnitOfWork.GetService <IReviewService>();
            FacadeUpdateResult <ReviewData> result = new FacadeUpdateResult <ReviewData>();
            Review instance = RetrieveOrNew <ReviewData, Review, IReviewService>(result.ValidationResult, instanceId);

            if (result.IsSuccessful)
            {
                return(converter.Convert(instance.RetrieveData <ReviewData>()));
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        internal TDto RetrieveOrNewApplicationSetting <TDto>(object instanceId, IDataConverter <ApplicationSettingData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("converter", converter);
            IApplicationSettingService service = UnitOfWork.GetService <IApplicationSettingService>();
            FacadeUpdateResult <ApplicationSettingData> result = new FacadeUpdateResult <ApplicationSettingData>();
            ApplicationSetting instance = RetrieveOrNew <ApplicationSettingData, ApplicationSetting, IApplicationSettingService>(result.ValidationResult, instanceId);

            if (result.IsSuccessful)
            {
                return(converter.Convert(instance.RetrieveData <ApplicationSettingData>()));
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        internal TDto RetrieveUser <TDto>(object id, IDataConverter <UserData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("converter", converter);
            IUserService service = UnitOfWork.GetService <IUserService>();
            FacadeUpdateResult <UserData> result = new FacadeUpdateResult <UserData>();
            User user = RetrieveOrNew <UserData, User, IUserService>(result.ValidationResult, id);

            if (result.IsSuccessful)
            {
                return(converter.Convert(user.RetrieveData <UserData>()));
            }
            else
            {
                return(null);
            }
        }
Exemple #8
0
        internal TDto RetrieveOrNewProject <TDto>(object projectId, IDataConverter <ProjectData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("converter", converter);
            IProjectService service = UnitOfWork.GetService <IProjectService>();
            FacadeUpdateResult <ProjectData> result = new FacadeUpdateResult <ProjectData>();
            Project project = RetrieveOrNew <ProjectData, Project, IProjectService>(result.ValidationResult, projectId);

            if (result.IsSuccessful)
            {
                return(converter.Convert(project.RetrieveData <ProjectData>()));
            }
            else
            {
                return(null);
            }
        }
        public override IEnumerable <object[]> GetData(MethodInfo testMethod)
        {
            if (!System.IO.File.Exists(File))
            {
                throw new FileNotFoundException("Test data not found", "File");
            }

            IDataConverter[] converters = testMethod.GetParameters()
                                          .Select(param => DataConverterFactory.Create(param.ParameterType))
                                          .ToArray();

            string text = System.IO.File.ReadAllText(File);

            if (string.IsNullOrWhiteSpace(text))
            {
                yield break;
            }

            string[] contents = TEST_PATTERN.Split(text)
                                .Select(content => content.Trim('\r', '\n'))
                                .Where(content => !string.IsNullOrWhiteSpace(content))
                                .ToArray();

            foreach (string content in contents)
            {
                string[] parameters = PARAM_PATTERN.Split(content)
                                      .Select(section => section.Trim('\r', '\n'))
                                      .Where(section => !string.IsNullOrWhiteSpace(section))
                                      .ToArray();

                if (parameters.Length != converters.Length)
                {
                    throw new ArgumentOutOfRangeException("Test parameters count different from test arguments count");
                }

                object[] result = new object[parameters.Length];
                for (int index = 0; index < parameters.Length; index++)
                {
                    string         param    = parameters[index];
                    IDataConverter provider = converters[index];
                    result[index] = provider.Convert(param);
                }

                yield return(result);
            }
        }
        internal TDto RetrieveOrNewLanguagePhrase <TDto>(object instanceId, IDataConverter <LanguagePhraseData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("converter", converter);
            ILanguagePhraseService service = UnitOfWork.GetService <ILanguagePhraseService>();
            FacadeUpdateResult <LanguagePhraseData> result = new FacadeUpdateResult <LanguagePhraseData>();
            LanguagePhrase instance = RetrieveOrNew <LanguagePhraseData, LanguagePhrase, ILanguagePhraseService>(result.ValidationResult, instanceId);

            if (result.IsSuccessful)
            {
                return(converter.Convert(instance.RetrieveData <LanguagePhraseData>()));
            }
            else
            {
                return(null);
            }
        }
        internal TDto CreateNewTask <TDto>(object projectId, IDataConverter <TaskData, TDto> converter)
            where TDto : class
        {
            ArgumentValidator.IsNotNull("projectId", projectId);
            ArgumentValidator.IsNotNull("converter", converter);

            IProjectService service = UnitOfWork.GetService <IProjectService>();
            var             query   = service.Retrieve(projectId);

            if (query.HasResult)
            {
                Project project = query.ToBo <Project>();
                Task    task    = RetrieveOrNewTask(project, null);
                if (task != null)
                {
                    return(converter.Convert(task.RetrieveData <TaskData>()));
                }
            }

            return(null);
        }
        public void AddToCart(CartDto cart, object productId, int quantity, IDataConverter <ProductInfoData, CartItemDto> converter)
        {
            // Check if already exist
            CartItemDto cartItem = cart.CartItems.SingleOrDefault(o => object.Equals(o.ProductId, productId));

            if (cartItem != null)
            {
                cartItem.QtyOrdered += quantity;
            }
            else
            {
                IProductService service = UnitOfWork.GetService <IProductService>();
                var             query   = service.RetrieveProductInfo(productId);

                if (query.HasResult)
                {
                    cartItem            = converter.Convert(query.Data);
                    cartItem.QtyOrdered = quantity;
                    cart.CartItems.Add(cartItem);
                }
            }
            cartItem.Amount = cartItem.UnitPrice * cartItem.QtyOrdered;
            CalculateCart(cart);
        }
        public IEnumerable <CustomerData> FindAll()
        {
            var customers = _customerRepository.FindAll();

            return(_dataConverter.Convert <IEnumerable <Customer>, IEnumerable <CustomerData> >(customers));
        }