Exemplo n.º 1
0
        public void InverseOfNonReadOnly()
        {
            var nonReadOnlyInverse = ValidDictionary.Inverse();

            Assert.That(nonReadOnlyInverse, Is.TypeOf <Dictionary <string, int> >());
            Assert.That(nonReadOnlyInverse, Is.Not.TypeOf <ReadOnlyDictionary <string, int> >());
        }
Exemplo n.º 2
0
        public void ItReturnsAnUnauthorizedHttpStatusWhenThereIsAGamingGroupIdThatDoesntMatchTheCurrentUser()
        {
            const string TOKEN = "TEST";

            request.Headers.Add(ApiAuthenticationAttribute.AUTH_HEADER, new[] { TOKEN });
            const int REQUESTED_GAMING_GROUP_ID = 1;

            actionContext.ActionArguments.Add("gamingGroupId", REQUESTED_GAMING_GROUP_ID);
            const int GAMING_GROUP_ID = -1;
            var       expectedUser    = new ApplicationUser
            {
                Id = "some id",
                CurrentGamingGroupId = GAMING_GROUP_ID
            };

            authTokenValidatorMock.Expect(mock => mock.ValidateAuthToken(TOKEN)).Return(expectedUser);
            const string EXPECTED_CLIENT_ID = "some client id";

            clientIdCalculatorMock.Expect(mock => mock.GetClientId(request, expectedUser)).Return(EXPECTED_CLIENT_ID);

            attribute.OnActionExecuting(actionContext);

            Assert.That(actionContext.Response.Content, Is.TypeOf(typeof(ObjectContent <HttpError>)));
            var content   = actionContext.Response.Content as ObjectContent <HttpError>;
            var httpError = content.Value as HttpError;

            Assert.That(actionContext.Response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            Assert.That(httpError.Message, Is.EqualTo(string.Format(ApiAuthenticationAttribute.ERROR_MESSAGE_UNAUTHORIZED_TO_GAMING_GROUP, REQUESTED_GAMING_GROUP_ID)));
        }
Exemplo n.º 3
0
        public void B()
        {
            var enumBM = new EnumBM <TestEnum>();

            enumBM.Metadata.DataProvider.Data = TestEnum.A;
            Assert.IsNotNull(enumBM.Settings);
            Assert.IsTrue(enumBM.Settings.IncludeValuesSpecified);
            Assert.IsNotNull(enumBM.Settings.IncludeValues);

            var enumVM = new EnumVM <TestEnum> {
                Metadata = new BusinessValueMetadata <TestEnum>()
            };

            ((BusinessValueDataProvider <TestEnum>)enumVM.Metadata.DataProvider).BusinessValue = enumBM;

            Assert.That(enumVM.DisplayValueProvider, Is.TypeOf <EnumDisplayValueProvider>());

            Assert.AreEqual(TestEnum.A, enumVM.Value);
            Assert.AreEqual("A", enumVM.DisplayValueProvider.String);
            Assert.AreEqual("A", enumVM.EditValueProvider.String);

            Assert.IsNotNull(enumVM.ValueSourceProvider);
            Assert.IsNotNull(enumVM.ValueSourceProvider.SourceList);

            var validValues = enumVM.ValueSourceProvider.SourceList.Cast <EnumMemberVM <TestEnum> >().ToList();

            Assert.AreEqual(3, validValues.Count);

            enumVM.Value = TestEnum.B;
            Assert.AreEqual(TestEnum.B, enumBM.Value);

            enumVM.EditValueProvider.String = "C";
            Assert.IsFalse(enumVM.ErrorProvider.HasError);
            Assert.AreEqual(TestEnum.C, enumBM.Value);
        }
Exemplo n.º 4
0
        public void InverseOfReadOnly()
        {
            var readOnly        = new ReadOnlyDictionary <int, string>(ValidDictionary);
            var readOnlyInverse = readOnly.Inverse();

            Assert.That(readOnlyInverse, Is.TypeOf <ReadOnlyDictionary <string, int> >());
            Assert.That(readOnlyInverse, Is.Not.TypeOf <Dictionary <string, int> >());
        }
Exemplo n.º 5
0
 public void Test_Compute()
 {
     AssertAll.Of(
         $"{nameof(Coercively)}.{nameof(Coercively.Compute)}: [{AType.Name}]{A} {Operation} [{BType.Name}]{B} == [{EType.Name}]{E}",
         Coercively.Compute(A, Operation, B),
         Is.EqualTo(E),
         Is.TypeOf(EType)
         );
 }
Exemplo n.º 6
0
        public void ShouldReturnBadRequestWhenNoTokenProvided()
        {
            attribute.OnActionExecuting(actionContext);

            Assert.That(actionContext.Response.Content, Is.TypeOf(typeof(ObjectContent <HttpError>)));
            var content   = actionContext.Response.Content as ObjectContent <HttpError>;
            var httpError = content.Value as HttpError;

            Assert.That(actionContext.Response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(httpError.Message, Is.EqualTo(ApiAuthenticationAttribute.ERROR_MESSAGE_MISSING_AUTH_TOKEN_HEADER));
        }
Exemplo n.º 7
0
        public void ShouldReturnBadRequestWhenTokenHasEmptyValue()
        {
            request.Headers.Add(ApiAuthenticationAttribute.AUTH_HEADER, new [] { string.Empty });
            attribute.OnActionExecuting(actionContext);

            Assert.That(actionContext.Response.Content, Is.TypeOf(typeof(ObjectContent <HttpError>)));
            var content   = actionContext.Response.Content as ObjectContent <HttpError>;
            var httpError = content.Value as HttpError;

            Assert.That(actionContext.Response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.That(httpError.Message, Is.EqualTo(ApiAuthenticationAttribute.ERROR_MESSAGE_INVALID_AUTH_TOKEN));
        }
Exemplo n.º 8
0
        public void ShouldReturnUnauthorizedHttpStatusWhenTokenExpired()
        {
            const string EXPECTED_TOKEN = "TEST";

            request.Headers.Add(ApiAuthenticationAttribute.AUTH_HEADER, new[] { EXPECTED_TOKEN });

            attribute.OnActionExecuting(actionContext);

            Assert.That(actionContext.Response.Content, Is.TypeOf(typeof(ObjectContent <HttpError>)));
            var content   = actionContext.Response.Content as ObjectContent <HttpError>;
            var httpError = content.Value as HttpError;

            Assert.That(actionContext.Response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            Assert.That(httpError.Message, Is.EqualTo(ApiAuthenticationAttribute.ERROR_MESSAGE_INVALID_AUTH_TOKEN));
        }
Exemplo n.º 9
0
 public void PrependMessage_KnownType()
 {
     try {
         throw new NullReferenceException(Original);
     }
     catch (NullReferenceException e) {
         var e2 = e.PrependMessage(Prepended);
         AssertAll.Of(
             e2,
             Is.Not.Null,
             Has.Property(nameof(e2.Message)).StartsWith(Prepended),
             Has.Property(nameof(e2.Message)).EndsWith(Original),
             Is.TypeOf <NullReferenceException>()
             );
     }
 }
Exemplo n.º 10
0
        public void ShouldReturnUnauthorizedHttpStatusWhenWrongToken()
        {
            const string TOKEN = "DIFFERENT";

            request.Headers.Add(ApiAuthenticationAttribute.AUTH_HEADER, new[] { TOKEN });

            authTokenValidatorMock.Expect(mock => mock.ValidateAuthToken(Arg <string> .Is.Anything)).Return(null);

            attribute.OnActionExecuting(actionContext);

            Assert.That(actionContext.Response.Content, Is.TypeOf(typeof(ObjectContent <HttpError>)));
            var content   = actionContext.Response.Content as ObjectContent <HttpError>;
            var httpError = content.Value as HttpError;

            Assert.That(actionContext.Response.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
            Assert.That(httpError.Message, Is.EqualTo(ApiAuthenticationAttribute.ERROR_MESSAGE_INVALID_AUTH_TOKEN));
        }
Exemplo n.º 11
0
            public void Test_Verb()
            {
                Func <object, object, object> method = Operation switch {
                    Coercive.Operation.Plus => Coercively.Add,
                    Coercive.Operation.Minus => Coercively.Subtract,
                    Coercive.Operation.Times => Coercively.Multiply,
                    Coercive.Operation.DividedBy => Coercively.Divide,
                    _ => throw EnumUtils.InvalidEnumArgumentException(nameof(Operation), Operation)
                };

                AssertAll.Of(
                    $"Coercively.{Operation.Operator().Verb}()-ing [{AType.Name}]{A}, [{BType.Name}]{B}",
                    method.Invoke(A, B),
                    Is.EqualTo(E),
                    Is.TypeOf(EType)
                    );
            }
        }
Exemplo n.º 12
0
        public void TestIssue70()
        {
            var serializer = MessagePackSerializer.Get <DBNull>(new SerializationContext());

#if !UNITY
            // Should not be created dynamically.
            Assert.That(serializer, Is.TypeOf(typeof(DefaultSerializers.System_DBNullMessagePackSerializer)));
#endif // !UNITY

            using (var buffer = new MemoryStream())
            {
                serializer.Pack(buffer, DBNull.Value);

                buffer.Position = 0;
                var packed = Unpacking.UnpackObject(buffer);
                Assert.That(packed.IsNil, packed.ToString());

                buffer.Position = 0;
                var unpacked = serializer.Unpack(buffer);
                Assert.That(Object.ReferenceEquals(unpacked, null), Is.False);
                Assert.That(unpacked, Is.SameAs(DBNull.Value));
            }
        }
Exemplo n.º 13
0
 public void InitializeShouldThrowExceptionOnMissingScriptProperty()
 {
     grinderContextMock.Setup(c => c.GetProperty(worker.ScriptFileKey)).Returns((string)null);
     Assert.Throws(Is.TypeOf <ArgumentException>().And.Message.EqualTo("Missing property 'grinderscript-dotnet.csScriptWorker.script'"), () => worker.Initialize());
 }
Exemplo n.º 14
0
 public void InitializeShouldLoadValidDuckTypeScript()
 {
     grinderContextMock.Setup(c => c.GetProperty(worker.ScriptFileKey)).Returns("CsScriptWorkerThatIsValidDuckType.txt");
     Assert.Throws(Is.TypeOf <ArgumentException>().And.Message.EqualTo("Type 'CsScriptWorkerThatIsValidDuckType', from script file 'CsScriptWorkerThatIsValidDuckType.txt', does not implement 'GrinderScript.Net.Core.IGrinderWorker'"), () => worker.Initialize());
     Assert.That(worker.ScriptWorker, Is.Not.Null);
 }