public void ToExpandoObjectConvertsNullDynamicToNullExpandoObject()
        {
            // arrange

            // act
            var destinationExpandoObject = DynamicObjectHelper.ToExpandoObject(null);

            // assert
            Assert.IsNull(destinationExpandoObject);
        }
        public void HasPropertyPropertyNotExistsOnExpandoObjectReturnsFalse()
        {
            // arrange
            var sourceDynamicObject      = new { };
            var destinationExpandoObject = DynamicObjectHelper.ToExpandoObject(sourceDynamicObject);

            // act
            var hasProperty = DynamicObjectHelper.HasProperty(destinationExpandoObject, "Property");

            // assert
            Assert.IsFalse(hasProperty);
        }
Example #3
0
        public static void Configure(this IHateoasContainer source, dynamic vars)
        {
            var container = source as HateoasContainer;

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            container.Configuration.Extend((ExpandoObject)DynamicObjectHelper.ToExpandoObject(vars));
            container.Update();
        }
        public void ToExpandoObjectReturnsExpandObjectIfDynamicObjectAlreadyIsExpandoObject()
        {
            // arrange
            var sourceDynamicObject = new { };
            var sourceExpandoObject = DynamicObjectHelper.ToExpandoObject(sourceDynamicObject);

            // act
            var destinationExpandoObject = DynamicObjectHelper.ToExpandoObject(sourceExpandoObject);

            // assert
            Assert.IsNotNull(destinationExpandoObject);
            Assert.AreSame(sourceExpandoObject, destinationExpandoObject);
        }
        public void ToExpandoObjectConvertsDynamicToExpandobjectAndIsUsableAsIDictionary()
        {
            // arrange
            const string property1Value      = "";
            const int    property2Value      = 0;
            var          sourceDynamicObject = new { Property1 = property1Value, Property2 = property2Value };

            // act
            var destinationExpandoObject = DynamicObjectHelper.ToExpandoObject(sourceDynamicObject);

            // assert
            Assert.IsNotNull(destinationExpandoObject);
            var destinationDictionaryObject = (IDictionary <string, object>)destinationExpandoObject;

            Assert.AreEqual(property1Value, destinationDictionaryObject["Property1"]);
            Assert.AreEqual(property2Value, destinationDictionaryObject["Property2"]);
        }
        public void Init()
        {
            _mockGetAssessmentOrgs = new Mock <IGetAssessmentOrgs>();
            _mockLogger            = new Mock <ILogger <AssessmentOrgsController> >();

            _mockUrlHelper = new Mock <IUrlHelper>();
            _mockUrlHelper.Setup(x => x.Link("GetAssessmentOrgById", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/assessment-organisations/{o.id}"); });
            _mockUrlHelper.Setup(x => x.Link("GetStandardById", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/Standards/{o.id}"); });
            _mockUrlHelper.Setup(x => x.Link("GetStandardsByAssessmentOrgId", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/assessment-organisations/{o.organisationId}/standards"); });

            _sut = new AssessmentOrgsController(
                _mockGetAssessmentOrgs.Object,
                _mockLogger.Object);

            _sut.Url = _mockUrlHelper.Object;
        }
        public void Init()
        {
            _lastDateForNewStarts = DateTime.Today.AddDays(100);
            _mockGetStandards     = new Mock <IGetStandards>();
            _mockLogger           = new Mock <ILogger <StandardsController> >();
            _mockUrlHelper        = new Mock <IUrlHelper>();
            _mockUrlHelper.Setup(x => x.Link("GetStandardById", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/standards/{o.id}"); });


            _sut     = new StandardsController(_mockGetStandards.Object, _mockLogger.Object);
            _sut.Url = _mockUrlHelper.Object;
        }
        public void Init()
        {
            _mockGetFrameworks = new Mock <IGetFrameworks>();
            _mockLogger        = new Mock <ILogger <FrameworksController> >();
            _mockUrlHelper     = new Mock <IUrlHelper>();
            _mockUrlHelper.Setup(x => x.Link("GetFrameworkById", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/frameworks/{o.id}"); });
            _mockUrlHelper.Setup(x => x.Link("GetByFrameworkCode", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/frameworks/codes/{o.frameworkCode}"); });

            _sut     = new FrameworksController(_mockGetFrameworks.Object, _mockLogger.Object);
            _sut.Url = _mockUrlHelper.Object;
        }
        public void Init()
        {
            _mockGetProviders     = new Mock <IGetProviders>();
            _mockControllerHelper = new Mock <IControllerHelper>();
            _mockGetStandards     = new Mock <IGetStandards>();
            _mockGetFrameworks    = new Mock <IGetFrameworks>();
            _mockUrlHelper        = new Mock <IUrlHelper>();
            _mockUrlHelper.Setup(x => x.Link("GetProviderByUkprn", It.IsAny <object>())).Returns <string, dynamic>((a, b) => { var o = DynamicObjectHelper.ToExpandoObject(b); return($"http://localhost/providers/{o.ukprn}"); });

            _sut = new ProvidersController(
                _mockGetProviders.Object,
                _mockControllerHelper.Object,
                _mockGetStandards.Object,
                _mockGetFrameworks.Object,
                Mock.Of <IApprenticeshipProviderRepository>()
                );

            _sut.Url = _mockUrlHelper.Object;
        }