public async Task ShouldReturnSuccess_WhenService_GetStackById() { // Arrange var stackId = StackIds.BackEndFrameworks; Stack stack = StackFake.GetStackById(stackId); var stackResponse = new StackResponse { StackId = stack.StackId, StackName = stack.StackName }; _stackRepository.Setup(m => m.GetStackByStackId(It.IsAny <StackIds>())).Returns(Task.FromResult(stack)); _mapper.Setup(m => m.Map <StackResponse>(stack)).Returns(stackResponse); // Act StackResponse result = await _stackService.GetStackByStackId(stackId); // Assert Assert.NotNull(result); Assert.Equal(stack.StackId, result.StackId); Assert.Equal(stack.StackName, result.StackName); }
public async Task <int> OnExecute(CommandLineApplication app, IConsole console) { var options = new ContentstackOptions { ApiKey = ApiKey, Authtoken = Authtoken, Host = Host }; var client = new ContentstackClient(options); try { Console.WriteLine($"Fetching Stack details for API Key {ApiKey}"); stack = await client.GetStack(); } catch (Exception e) { Console.WriteLine(e); Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("There was an error communicating with the Contentstack API: " + e.Message); Console.Error.WriteLine("Please verify that your api key and authtoken are correct"); return(Program.ERROR); } var path = ""; if (string.IsNullOrEmpty(Path)) { path = Directory.GetCurrentDirectory(); Console.WriteLine($"No path specified, creating files in current working directory {path}"); } else { Console.WriteLine($"Path specified. Files will be created at {Path}"); path = Path; } path = $"{path}/Models"; DirectoryInfo dir = CreateDirectory(path); try { Console.WriteLine($"Fetching Content Types from {stack.Name}"); var totalCount = await getContentTypes(client, 0); var skip = 100; Console.WriteLine($"Found {totalCount} Content Types ."); while (totalCount > skip) { Console.WriteLine($"{skip} Content Types Fetched."); totalCount = await getContentTypes(client, skip); skip += 100; } Console.WriteLine($"Total {totalCount} Content Types fetched."); CreateEmbeddedObjectClass(Namespace, dir); Console.WriteLine($"Fetching Global Fields from {stack.Name}"); totalCount = await getGlobalFields(client, 0); skip = 100; Console.WriteLine($"Found {totalCount} Global Fields."); while (totalCount > skip) { Console.WriteLine($"{skip} Global Fields Fetched."); totalCount = await getGlobalFields(client, skip); skip += 100; } Console.WriteLine($"Total {totalCount} Global Fields fetched."); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("There was an error communicating with the Contentstack API: " + e.Message); Console.Error.WriteLine("Please verify that your api key and authtoken are correct"); return(Program.ERROR); } Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Generating files from content type"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.DarkYellow; CreateLinkClass(Namespace, dir); CreateHelperClass(Namespace, dir); CreateStringHelperClass(Namespace, dir); CreateDisplayAttributeClass(Namespace, dir); foreach (var contentType in _contentTypes) { CreateFile(FormatClassName(contentType.Title), Namespace, contentType, dir); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Files successfully created!"); Console.ResetColor(); Console.WriteLine($"Opening {dir.FullName}"); OpenFolderatPath(dir.FullName); return(Program.OK); }