Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinfactory committed Jan 24, 2020
1 parent 65c0561 commit 81918b1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backlog.md
@@ -1,10 +1,9 @@
# Roadmap

- update dotnetcore workflow to use sln, to simplify build.
- Add support to fields to Form.Write #44

## Busy next

- Add support to fields to Form.Write #44
- simple input, ReadLine()
- create proper highspeedwriter interface that's used by the private highspeed writer, or App? so that the interface is real and not fakes.
- write Mac HighSpeedWriter and test locally
Expand Down Expand Up @@ -36,6 +35,7 @@
- do pull request and squash commits after a nice cleanup so that my commits can be easier to read.
- OpenBox
- list view :D
- move .source.md files to seperate folder. (mdsnippets)
- fix bug - when creating an inline window from an new ConcurrentWriter() IConsole the colors are wrong? See spike "paul".
- NB! Set scrollable region (using VT100 commands!)
- so that you can have input region at the bottom, and "app" at the top?
Expand Down
6 changes: 6 additions & 0 deletions change-log.md
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [6.2.0]

### Added

- Form Write now supports fields as well as properties.

## [6.1.0]

### Added
Expand Down
38 changes: 38 additions & 0 deletions src/Konsole.Tests/FormTests/WriteShould.cs
Expand Up @@ -7,7 +7,45 @@ namespace Konsole.Tests.FormTests
{
public class WriteShould
{
internal class Cat
{
public Cat(int age, string breed, string name)
{
Breed = breed;
Age = age;
Name = name;
}
public static string StarSign = "LEO";
public int Age;
public string Breed { get; set; }
private string Breeder { get; set; } = "private";
public string Name;
public int NumberOfKittens = 3;
}

[Test]
public void print_public_properties_then_fields()
{
var console = new MockConsole(80, 20);
var form = new Form(console);
var cat = new Cat(10, "Tabby", "Fred");
console.WriteLine("line1");
form.Write(cat);
console.WriteLine("line2");
var expected = new[]
{
"line1",
" ┌──────────────────────────────────── Cat ────────────────────────────────────┐",
" │ Breed : Tabby │",
" │ Age : 10 │",
" │ Name : Fred │",
" │ Number Of Kittens : 3 │",
" └─────────────────────────────────────────────────────────────────────────────┘",
"line2"
};

console.BufferWrittenTrimmed.Should().BeEquivalentTo(expected);
}
[Test]
public void show_the_form_inline_at_the_next_line_below_current_cursor_position_and_update_cursor()
{
Expand Down
9 changes: 8 additions & 1 deletion src/Konsole.Tests/Internal/Person.cs
@@ -1,12 +1,19 @@
namespace Konsole.Tests.TestClasses
{
public class Person
internal class Person
{
public Person()
{
Address = new Address();
}

public static string StarSign = "LEO";

public static decimal Height
{
get { return 10.5M; }
}

public string FirstName { get; set; }
public string LastName { get; set; }
public string AFieldWithAMuchLongerName { get; set; }
Expand Down
26 changes: 21 additions & 5 deletions src/Konsole/Forms/FieldReader.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Konsole.Forms
Expand Down Expand Up @@ -39,9 +40,12 @@ public FieldReader(object @object)
typeof (DateTime)
}.Concat(NumericTypes).ToArray();

/// <summary>
/// reads the simple non generic public fields and properties that are numbers, strings, dateTime and booleans.
/// </summary>
public FieldList ReadFieldList()
{
var fields = readFields();
var fields = readPropertiesAndFields();
int width = fields.Any() ? fields.Max(f => f.Caption.Length) : 10;
var fieldlist = new FieldList(fields.ToArray(), width);
return fieldlist;
Expand All @@ -60,22 +64,34 @@ public static bool IsNumericType(Type type)
}


private IEnumerable<Field> readFields()
private IEnumerable<Field> readPropertiesAndFields()
{
var properties = _type.GetProperties();
var fields = _type.GetFields( BindingFlags.Public | BindingFlags.Instance);
var supportedFields = fields.Where(f => SupportedTypes.Contains(NonGenericType(f.FieldType)));

var properties = _type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
var supportedProps = properties
.Where(f => SupportedTypes.Contains(NonGenericType(f.PropertyType)));

var fields = supportedProps
var _props = supportedProps
.Select(f => new Field(
ParseFieldType(f.PropertyType),
f.Name,
ToCaption(f.Name),
IsNullable(f.PropertyType),
f.GetValue(_object)
));
return fields;
var _fields = supportedFields
.Select(f => new Field(
ParseFieldType(f.FieldType),
f.Name,
ToCaption(f.Name),
IsNullable(f.FieldType),
f.GetValue(_object)
));

var fieldsAndProps = _props.Concat(_fields);
return fieldsAndProps;
}

public static FieldType ParseFieldType(Type type)
Expand Down

0 comments on commit 81918b1

Please sign in to comment.