Ejemplo n.º 1
0
        public void TestAmmendSpecificationMapsAllAliasesToExpectedNativeTypesOnEmptySpec()
        {
            // arrange
            var spec = new Spec {
                Targets = new Dictionary <string, TargetInfo> {
                    { Constants.TypeScriptTarget, new TargetInfo() }
                }
            };
            var ammendment = new TypeScriptAmmendment();

            // act
            ammendment.AmmedSpecification(spec);

            // assert
            var typeAliases = spec.Targets[Constants.TypeScriptTarget].TypeAliases.ToList();

            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("bool", "boolean")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("char", "string")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("byte", "number")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("short", "number")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("int", "number")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("long", "string")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("float", "number")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("double", "number")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("decimal", "string")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("string", "string")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("object", "any")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("time", "Date")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("date", "Date")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("datetime", "Date")));
            Assert.True(typeAliases.Remove(new KeyValuePair <string, string>("guid", "string")));
            Assert.True(typeAliases.Count == 0, "Additional TypeAliases present than those that were tested. Adjust your code and/or unit test.");
        }
Ejemplo n.º 2
0
        public void TestAmmendSpecificationFailsToReplaceBuiltinTypes()
        {
            // arrange
            var spec =
                new Spec
            {
                Targets = new Dictionary <string, TargetInfo>
                {
                    { Constants.TypeScriptTarget,
                      new TargetInfo
                      {
                          TypeAliases = new Dictionary <string, string>
                          {
                              { "datetime", "MyDate" }
                          }
                      } }
                }
            };
            var ammendment = new TypeScriptAmmendment();
            var exception  = (Exception)null;

            // act
            try { ammendment.AmmedSpecification(spec); } catch (Exception ex) { exception = ex; }

            // assert
            Assert.NotNull(exception);
        }