c# - Test my json data parser should return a logger -
let's @ json string structure.
so there 7 loggers, let's expand nodes details.
{ "root_logger" : "myfailoverlogger", "loggers": [ { "logger_name": "myfilelogger", "logger_type": "mycompany.loggers.filesystemlogger", "layout": "${message}|${exception}", "stack_trace": { "error": true, "fatal": false }, "file_path_pattern" : "\\\\corporate.mycompany.com\\data\\recordings\\logs\\yyyy\\mm\\dd", "file_name_pattern" : "app.{mmddhhmm}.log", "rollover_after_n_hours" : 5, "rollover_after_n_megabytes": 5, "level" : { "min_level" : "info", "max_level" : "debug" } }, { "logger_name" : "mydblogger", "logger_type" : "mycompany.loggers.databaselogger", "connection_string" : "", "target_table" : "", "command_timeout_milliseconds" : 100, "layout" : "${message}", "level" : { "min_level" : "info", "max_level" : "debug" } },
i not sure how test have primary code here.
[theory] [inlinedata("myfilelogger")] [inlinedata("mydblogger")] [inlinedata("mydblogger2")] [inlinedata("myconsolelogger")] [inlinedata("mynulllogger")] [inlinedata("mymultiplexinglogger")] [inlinedata("myfailoverlogger")] public void jsonconfigurationfileparser_should_return_a_logger_given_a_name(string expextedloggername) { // arrange var currentfilepath = environment.currentdirectory + @"\mycompanyconfiguration.json"; var jsonstring = file.readalltext(currentfilepath); var jsonconfigurationfileparser = new jsonconfigurationfileparser(jsonstring); // act var actualloggers = jsonconfigurationfileparser.deserializelogger();// collection. // assert }
the actualloggers
return 7 loggers. question not sure how test properly. should use inlinedata
or else? left assert part empty now. way, using moq okay.
since inlinedata parameter call test once each of attributes. need add search in deserialized object find particular node expecting see.
since don't show deserialized format is, guess in example.
[theory] [inlinedata("myfilelogger")] [inlinedata("mydblogger")] [inlinedata("mydblogger2")] [inlinedata("myconsolelogger")] [inlinedata("mynulllogger")] [inlinedata("mymultiplexinglogger")] [inlinedata("myfailoverlogger")] public void jsonconfigurationfileparser_should_return_a_logger_given_a_name(string expectedloggername) { // arrange var currentfilepath = environment.currentdirectory + @"\mycompanyconfiguration.json"; var jsonstring = file.readalltext(currentfilepath); var jsonconfigurationfileparser = new jsonconfigurationfileparser(jsonstring); // act var actualloggers = jsonconfigurationfileparser.deserializelogger(); // assert assert.true(actualloggers.any(x=> x.name == expectedloggername)); }
at point need decide whether generic test testing parser, in case throwing few different configuration files @ parser , writing specific tests scenarios (i.e. badly formed file, single logger, multiple loggers, etc.) these tests should prove parser working correctly.
a test case yours specific show each logger parsed, plus perhaps 1 additional test without inlinedata parameters show correct number of total nodes parsed good.
Comments
Post a Comment