Ejemplo n.º 1
0
        public OperationSerializerTests()
        {
            ResourceType intType = ResourceType.GetPrimitiveResourceType(typeof(int));

            var customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "Customer", false);

            customerType.CanReflectOnInstanceType = false;
            customerType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, intType)
            {
                CanReflectOnInstanceTypeProperty = false
            });
            customerType.SetReadOnly();

            var operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", intType) }, null);

            operation.SetReadOnly();
            this.baseTypeOperation = new OperationWrapper(operation);

            var bestCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, customerType, "FQ.NS", "BestCustomer", false);

            bestCustomerType.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", bestCustomerType) }, null);
            operation.SetReadOnly();
            this.derivedTypeOperation = new OperationWrapper(operation);

            operation = new ServiceAction("Unambiguous", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType) }, null);
            operation.SetReadOnly();
            this.unambiguousOperation = new OperationWrapper(operation);

            this.entityToSerialize = EntityToSerialize.CreateFromExplicitValues(new object(), bestCustomerType, new TestSerializedEntityKey("http://odata.org/Service.svc/Customers(0)/", bestCustomerType.FullName));

            this.testSubject = CreateOperationSerializer(AlwaysAdvertiseActions);
        }
Ejemplo n.º 2
0
        private static IEnumerable <TestOperation> DeserializeOperations(string serialized)
        {
            var byteArray = Encoding.ASCII.GetBytes(serialized);

            using (var stream = new MemoryStream(byteArray))
                using (var reader = new StreamReader(stream))
                    return(OperationSerializer.Deserialize(reader));
        }
        public void Test()
        {
            var clientId = Guid.NewGuid();
            var expected = new Operation(OperationType.Delete, new Char(new CharId(clientId, 0), "1", Char.Begin.Id, Char.End.Id));
            var actual   = OperationSerializer.Deserialize(OperationSerializer.Serialize(expected));

            Console.WriteLine(clientId);
            Console.WriteLine(OperationSerializer.Serialize(expected));
            Assert.AreEqual(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(actual));
        }
Ejemplo n.º 4
0
 private static string SerializeOperations(IEnumerable <TestOperation> operations)
 {
     using (var stream = new MemoryStream())
         using (var writer = new StreamWriter(stream))
             using (var reader = new StreamReader(stream))
             {
                 OperationSerializer.Serialize(writer, operations);
                 stream.Position = 0;
                 return(reader.ReadToEnd());
             }
 }
Ejemplo n.º 5
0
        public void Random_CustomOperations_ExecutedCorrectly()
        {
            var operationsPath = NUnit.Framework.TestContext.Parameters["RandomTestOperationsPath"];

            using (var reader = new StreamReader(operationsPath))
            {
                var clipTitle  = reader.ReadLine();
                var operations = OperationSerializer.Deserialize(reader);
                RunRandomOperationsTest(clipTitle, operations, false);
            }
        }
Ejemplo n.º 6
0
        private static void DumpOperations(string clipTitle, IEnumerable <TestOperation> operations)
        {
            var testName = NUnit.Framework.TestContext.CurrentContext.Test.Name
                           .Replace(" ", "-");
            var testDate = DateTime.Now.TimeOfDay.ToString()
                           .Replace(" ", "-")
                           .Replace(":", "-");
            var pid = Process.GetCurrentProcess().Id;

            var fullPath = Path.Combine(Path.GetTempPath(), $"{testName}_{pid}_{testDate}");

            using (var writer = new StreamWriter(fullPath))
            {
                writer.WriteLine(clipTitle);
                OperationSerializer.Serialize(writer, operations);
                Console.WriteLine($"Test operations dumped to {fullPath}");
            }
        }