public void testOperationOptionInfo()
 {
     OperationOptionInfo v1 =
         new OperationOptionInfo("name", typeof(int?));
     OperationOptionInfo v2 =
         (OperationOptionInfo)CloneObject(v1);
     Assert.AreEqual(v1, v2);
 }
 public void TestSchema()
 {
     OperationOptionInfo opInfo =
         new OperationOptionInfo("name", typeof(int?));
     ObjectClassInfoBuilder bld = new ObjectClassInfoBuilder();
     bld.ObjectType = ObjectClass.ACCOUNT_NAME;
     ObjectClassInfo info = bld.Build();
     ICollection<ObjectClassInfo> temp = CollectionUtil.NewSet(info);
     IDictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>> map =
         new Dictionary<SafeType<APIOperation>, ICollection<ObjectClassInfo>>();
     map[SafeType<APIOperation>.Get<CreateApiOp>()] = temp;
     ICollection<OperationOptionInfo> temp2 = CollectionUtil.NewSet(opInfo);
     IDictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>> map2 =
         new Dictionary<SafeType<APIOperation>, ICollection<OperationOptionInfo>>();
     map2[SafeType<APIOperation>.Get<CreateApiOp>()] = temp2;
     Schema v1 = new Schema(CollectionUtil.NewSet(info),
             CollectionUtil.NewSet(opInfo),
             map,
             map2);
     Schema v2 = (Schema)CloneObject(v1);
     Assert.AreEqual(v1, v2);
     Assert.AreEqual(info, v2.ObjectClassInfo.First());
     Assert.AreEqual(1, v2.SupportedObjectClassesByOperation.Count);
     Assert.AreEqual(1, v2.SupportedOptionsByOperation.Count);
     Assert.AreEqual(1, v2.OperationOptionInfo.Count);
 }
 /// <summary>
 /// Adds another OperationOptionInfo to the schema.
 /// </summary>
 /// <remarks>
 /// Also, adds this
 /// to the set of supported options for every operation defined by
 /// the Connector.
 /// </remarks>
 public void DefineOperationOption(OperationOptionInfo info)
 {
     Assertions.NullCheck(info, "info");
     if (_declaredOperationOptions.Contains(info))
     {
         throw new InvalidOperationException("OperationOption already defined: " +
                 info.Name);
     }
     _declaredOperationOptions.Add(info);
     foreach (SafeType<APIOperation> op in
         FrameworkUtil.GetDefaultSupportedOperations(_connectorClass))
     {
         ICollection<OperationOptionInfo> oclasses =
             CollectionUtil.GetValue(_supportedOptionsByOperation, op, null);
         if (oclasses == null)
         {
             oclasses = new HashSet<OperationOptionInfo>();
             _supportedOptionsByOperation[op] = oclasses;
         }
         oclasses.Add(info);
     }
 }
 /// <summary>
 /// Removes the given OperationOptionInfo as a supported option for
 /// the given operation.
 /// </summary>
 /// <param name="op">The SPI operation</param>
 /// <param name="def">The OperationOptionInfo</param>
 /// <exception cref="ArgumentException">If the given OperationOptionInfo was
 /// not already defined using <see cref="DefineOperationOption(OperationOptionInfo)" />.</exception>
 public void RemoveSupportedOperationOption(SafeType<SPIOperation> op,
     OperationOptionInfo def)
 {
     Assertions.NullCheck(op, "op");
     Assertions.NullCheck(def, "def");
     ICollection<SafeType<APIOperation>> apis =
         FrameworkUtil.Spi2Apis(op);
     if (!_declaredOperationOptions.Contains(def))
     {
         throw new ArgumentException("OperationOption " + def.Name +
                 " not defined in schema.");
     }
     foreach (SafeType<APIOperation> api in apis)
     {
         ICollection<OperationOptionInfo> infos =
             CollectionUtil.GetValue(_supportedOptionsByOperation, api, null);
         if (infos == null)
         {
             throw new ArgumentException("Operation " + op +
                     " not implement by connector.");
         }
         if (!infos.Contains(def))
         {
             throw new ArgumentException("OperationOption " + def.Name +
                     " already removed for operation " + op);
         }
         infos.Remove(def);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Adds another OperationOptionInfo to the schema. Also, adds this to the
 /// set of supported options for operation defined.
 /// </summary>
 /// <param name="info"> </param>
 /// <param name="operations">
 /// </param>
 /// <exception cref="InvalidOperationException">
 ///             If already defined </exception>
 public void DefineOperationOption(OperationOptionInfo info, params SafeType<SPIOperation>[] operations)
 {
     if (operations.Length > 0)
     {
         Assertions.NullCheck(info, "info");
         if (_declaredOperationOptions.Contains(info))
         {
             throw new InvalidOperationException("OperationOption already defined: " + info.Name);
         }
         _declaredOperationOptions.Add(info);
         foreach (SafeType<SPIOperation> spi in operations)
         {
             if (typeof(SchemaOp) == spi.RawType ||
                typeof(TestOp) == spi.RawType)
             {
                 continue;
             }
             IEnumerable<SafeType<APIOperation>> apiOperations = FrameworkUtil.Spi2Apis(spi).Intersect(_defaultSupportedOperations);
             foreach (SafeType<APIOperation> op in apiOperations)
             {
                 if (OperationOptionOperation(op))
                 {
                     ICollection<OperationOptionInfo> oclasses =
                         CollectionUtil.GetValue(_supportedOptionsByOperation, op, null);
                     if (oclasses == null)
                     {
                         oclasses = new HashSet<OperationOptionInfo>();
                         _supportedOptionsByOperation[op] = oclasses;
                     }
                     oclasses.Add(info);
                 }
             }
         }
     }
     else
     {
         DefineOperationOption(info);
     }
 }