Exemple #1
0
        public void Get_Composite_File_Collection_For_Url_Generation()
        {
            var files = new[] { "", "" };

            var urlHelper = new Mock<IUrlHelper>();
            urlHelper.Setup(x => x.Content(It.IsAny<string>())).Returns<string>(s => s);
            //var options = new SmidgeOptions();
            var appEnv = Mock.Of<IApplicationEnvironment>();
            var config = Mock.Of<ISmidgeConfig>();
            var hostingEnv = Mock.Of<IHostingEnvironment>();
            var fileSystemHelper = new FileSystemHelper(appEnv, hostingEnv, config, urlHelper.Object);
            //var helper = new SmidgeHelper(
            //    new SmidgeContext(Mock.Of<IUrlManager>()),
            //    config,
            //    new FileMinifyManager(fileSystemHelper, options),
            //    new FileSystemHelper(appEnv, hostingEnv, config),
            //    Mock.Of<IHasher>(),
            //    new BundleManager(fileSystemHelper),
            //    Mock.Of<IContextAccessor<HttpRequest>>(x => x.Value == Mock.Of<HttpRequest>()));

            var batcher = new FileBatcher(fileSystemHelper, Mock.Of<HttpRequest>(), Mock.Of<IHasher>());

            //test a mix start/ending with external
            var result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "http://cdnjs.cloudflare.com/ajax/libs/test2.min.js"),
                });

            Assert.Equal(4, result.Count());

            //start/end with internal
            result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test2.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world2.js"),
                });

            Assert.Equal(3, result.Count());

            //all internal
            result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test2.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world2.js"),
                });

            Assert.Equal(1, result.Count());

            //start internal/end external
            result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test2.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test.min.js"),
                });

            Assert.Equal(2, result.Count());

            //start external/end internal
            result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "hello/world.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "~/test/test2.js"),                    
                });

            Assert.Equal(2, result.Count());

            //all external
            result = batcher.GetCompositeFileCollectionForUrlGeneration(new IWebFile[] {
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test2.min.js"),
                    Mock.Of<IWebFile>(f => f.FilePath == "//cdnjs.cloudflare.com/ajax/libs/test3.min.js")
                });

            Assert.Equal(3, result.Count());
        }
Exemple #2
0
		private static void CreateWebpackConfigurationFile(WebpackOptions options) {
			if (!Directory.Exists("webpack")) {
				Directory.CreateDirectory("webpack");
			}
			var presets = new List<string>() {
				"es2015"
			};
			if (options.HandleJsxFiles) {
				presets.Add("react");
			}
			var query = new Query {
				Presets = presets
			};
			var loaders = new List<WebpackLoader>();
			loaders.Add(new WebpackLoader {
				Test = "/\\.js/",
				Loader = "babel-loader",
				Exclude = "/node_modules/",
				Query = query
			});
			if (options.HandleJsxFiles) {
				loaders.Add(new WebpackLoader {
					Test = "/\\.jsx/",
					Loader = "babel-loader",
					Exclude = "/node_modules/",
					Query = query
				});
			}
			var exports = new {
				module = new {
					loaders
				}
			};
			var jsonResult = JsonConvert.SerializeObject(exports,
				new JsonSerializerSettings {
					Formatting = Formatting.Indented,
					ContractResolver = new CamelCasePropertyNamesContractResolver()
				});
			var fileContent = $"module.exports = {jsonResult}";
			using (var fs = File.Create(Path.Combine("webpack", "webpack.dev.js"))) {
				using (var streamWriter = new StreamWriter(fs)) {
					streamWriter.WriteLine(fileContent);
				}
			}
		}
        public async Task AddEventAppOnly(
            string userObjectIdOrPrincipalName,
            string subject,
            DateTimeOffset startTime,
            DateTimeOffset endTime,
            IEnumerable<string> attendeeEmails,
            string description,
            string locationDisplayName)
        {
            var accessToken = await GetAppOnlyAccessToken(O365Config.AccessTokenUri);
            string api = string.Format(O365Config.EventsApiFormatString, O365Config.ApiBaseUrl, O365Config.TenantId, userObjectIdOrPrincipalName);

            var @event = new 
            {
                Subject = subject,
                Body = new
                {
                    ContentType =  BodyType.Text.ToString(),
                    Content = description
                },
                Start = new
                {
                    DateTime = startTime.UtcDateTime.ToString("o"),
                    TimeZone = "UTC"
                },
                End = new
                {
                    DateTime = endTime.UtcDateTime.ToString("o"),
                    TimeZone = "UTC"
                },
                Attendees = attendeeEmails.Select(a => new { EmailAddress = new { Address = a, Name = a } }).ToArray(),
                Location = new
                {
                    DisplayName = locationDisplayName
                }
            };

            var postData = JsonConvert.SerializeObject(@event);
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var content = new StringContent(postData, Encoding.UTF8, "application/json");
                var response = await client.PostAsync(api, content);
                if (!response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                    Debug.WriteLine("Unseccessful request: " + response);
                }
            }
        }