shaml 0.5.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/shaml ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'shaml/shaml'
4
+ Shaml::Command.run
@@ -0,0 +1,175 @@
1
+ require 'zip/zip'
2
+
3
+ module Shaml
4
+ class CommandLoader
5
+ def initialize
6
+ end
7
+
8
+ def getappname
9
+ appname = Dir.glob("*.sln").first
10
+ if appname.nil?
11
+ puts 'S#aml ERROR: solution file not found. Change directory to a s#aml-architecture project'
12
+ exit
13
+ end
14
+ appname.gsub(".sln","")
15
+ end
16
+
17
+ def camelcase(phrase)
18
+ phrase.gsub(/^[a-z]|[ _]+[a-z]/) { |a| a.upcase }.gsub(/[ _]/, '')
19
+ end
20
+
21
+ def unzip_file(file, destination)
22
+ Zip::ZipFile.open(file) { |zip_file|
23
+ zip_file.each { |f|
24
+ f_path=File.join(destination, f.name)
25
+ FileUtils.mkdir_p(File.dirname(f_path))
26
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
27
+ }
28
+ }
29
+ end
30
+
31
+ def convert_file(file, appname, modelname, propertydescriptor)
32
+ out = ""
33
+ pstring = ""
34
+ insideprop = false
35
+ file.each_line do |line|
36
+ out << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
37
+ end
38
+ out
39
+ end
40
+
41
+ def copy_file(from,to,appname,modelname,propertydescriptor)
42
+ outfname = to.gsub("WebSample",camelcase(modelname))
43
+ FileUtils.mkdir_p(File.dirname(outfname))
44
+ File.open(from,"rb") do |infile|
45
+ File.open(outfname,"wb+") do |outfile|
46
+ puts "Writing #{outfname}"
47
+ outfile.write convert_file(infile.read,appname,modelname,propertydescriptor)
48
+ end
49
+ end
50
+ end
51
+
52
+ def run
53
+ if ARGV.length == 0 then
54
+ puts "S#aml architecture: ASP.NET MVC 2 and NHibernate 2.1 on mono 2.4.4+"
55
+ puts " version: #{SHAML_VERSION}"
56
+ puts
57
+ puts "Usage:"
58
+ puts " shaml command [parameters]"
59
+ puts
60
+ puts "Where command might be:"
61
+ puts " generate"
62
+ puts " app AppName : Create new shaml application"
63
+ puts " resource ResName : Create new CRUD resource with"
64
+ puts " a model, a view and a controller"
65
+ puts " controller Controller : Create a standalone controller"
66
+ puts " model Model : Create a standalone model"
67
+ puts
68
+ puts " compile : Compiles the solution using xbuild"
69
+ puts " server : Runs xsp2"
70
+ puts
71
+ puts " console : Starts a csharp console"
72
+ puts " gconsole : Starts a gsharp console"
73
+ puts " runner script_name.cs : Runs the script"
74
+ puts
75
+ puts "Examples: "
76
+ puts " shaml generate app Blog"
77
+ puts " shaml generate resource Post"
78
+ puts " shaml compile"
79
+ puts
80
+ puts "The console, gconsole and runner parameters will preload the solutions"
81
+ puts "assemblies and configuration files, and loads everything you need to get"
82
+ puts "working with the domain objects"
83
+ else
84
+ command = ARGV.shift
85
+ case command
86
+ when "generate" then
87
+ type = ARGV.shift
88
+ name = ARGV.shift
89
+ if name then
90
+ case type
91
+ when "app" then
92
+ unzip_file(File.join(TEMPLATEDIR,"shaml_base_template.dat"), ".shaml_extract_temp")
93
+ Dir.glob(".shaml_extract_temp/**/*").each do |filename|
94
+ infname = filename
95
+ outfname = filename.gsub("WebBase",name).gsub(".shaml_extract_temp",name);
96
+ FileUtils.mkdir_p(File.dirname(outfname))
97
+ unless File.directory?(infname)
98
+ File.open(infname,"rb") do |infile|
99
+ File.open(outfname,"wb+") do |outfile|
100
+ puts "Writing #{outfname}"
101
+ if infname=~/\.dll/ then
102
+ outfile.write infile.read
103
+ else
104
+ outfile.write infile.read.gsub("WebBase",name);
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ FileUtils.rm_rf ".shaml_extract_temp"
111
+ when "resource"
112
+ desc = ARGV.shift || nil
113
+ appname = getappname
114
+ copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join(appname,"App","Models","WebSample.cs"),appname,name,desc)
115
+ copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join(appname,"App","Controllers","WebSamplesController.cs"),appname,name,desc)
116
+ copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join(appname,"App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc)
117
+ copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join(appname,"App","Views","WebSamples","Create.haml"),appname,name,desc)
118
+ copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join(appname,"App","Views","WebSamples","Delete.haml"),appname,name,desc)
119
+ copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join(appname,"App","Views","WebSamples","Edit.haml"),appname,name,desc)
120
+ copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join(appname,"App","Views","WebSamples","Index.haml"),appname,name,desc)
121
+ copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join(appname,"App","Views","WebSamples","Show.haml"),appname,name,desc)
122
+ copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join(appname+".Tests","Tests","Core","WebSampleTests.cs"),appname,name,desc)
123
+ copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join(appname+".Tests","Tests","Web","Controllers","WebSamplesControllerTests.cs"),appname,name,desc)
124
+ when "model"
125
+ desc = ARGV.shift || nil
126
+ appname = getappname
127
+ copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join(appname,"App","Models","WebSample.cs"),appname,name,desc)
128
+ copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join(appname+".Tests","Tests","Core","WebSampleTests.cs"),appname,name,desc)
129
+ when "controller"
130
+ desc = ARGV.shift || nil
131
+ appname = getappname
132
+ copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join(appname,"App","Controllers","WebSamplesController.cs"),appname,name,desc)
133
+ copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join(appname,"App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc)
134
+ copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join(appname,"App","Views","WebSamples","Create.haml"),appname,name,desc)
135
+ copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join(appname,"App","Views","WebSamples","Delete.haml"),appname,name,desc)
136
+ copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join(appname,"App","Views","WebSamples","Edit.haml"),appname,name,desc)
137
+ copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join(appname,"App","Views","WebSamples","Index.haml"),appname,name,desc)
138
+ copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join(appname,"App","Views","WebSamples","Show.haml"),appname,name,desc)
139
+ copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join(appname+".Tests","Tests","Web","Controllers","WebSamplesControllerTests.cs"),appname,name,desc)
140
+ else
141
+ puts 'S#aml ERROR: unknown generate argument'
142
+ end
143
+ else
144
+ puts 'S#aml ERROR: no name specified'
145
+ end
146
+ when "compile"
147
+ appname = getappname
148
+ puts "Copying libraries"
149
+ begin
150
+ FileUtils.rm_r(File.join(appname,"bin"))
151
+ rescue Exception => e
152
+ end
153
+ FileUtils.cp_r("libraries",File.join(appname,"bin"))
154
+ puts "Compiling using xbuild"
155
+ system("xbuild #{appname}.sln")
156
+ puts "Compiling stylesheets"
157
+ Dir.chdir(appname) do
158
+ system("compass --update -c Config/compass_config.rb")
159
+ end
160
+ when "server"
161
+ puts "Starting xsp2"
162
+ appname = getappname
163
+ Dir.chdir(appname) do
164
+ puts "Changed directory to #{Dir.pwd}"
165
+ puts "Starting xsp2 #{ARGV.join(" ")}"
166
+ system("xsp2 #{ARGV.join(" ")}")
167
+ puts "Done..."
168
+ end
169
+ else
170
+ puts 'S#aml ERROR: unknown command'
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,92 @@
1
+ require 'rbconfig'
2
+ require 'fileutils'
3
+
4
+ module Shaml
5
+ class MonoLoader
6
+ def initialize
7
+ @mono_command = '/bin/mono'
8
+ @mono_directory = '/usr'
9
+ @mono_lib_directory = '/lib'
10
+ @csharp_command = '/mono/2.0/csharp.exe'
11
+ @gsharp_command = '/gsharp/gsharp.exe'
12
+ @config_dir = '~/.config'
13
+ @init_script_name = 'shaml.cs'
14
+
15
+ # get mono path for Windows
16
+ if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw/i
17
+ begin
18
+ require 'win32/registry'
19
+ # Check in default location
20
+ base = "Software\\Novell\\Mono\\"
21
+ begin
22
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(base) do |reg|
23
+ end
24
+ # if running ruby 64-bit and mono 32-bit, change the registry search location
25
+ rescue Win32::Registry::Error
26
+ base = "Software\\Wow6432Node\\Novell\\Mono\\"
27
+ end
28
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(base) do |reg|
29
+ monoversion = reg.read_s("DefaultCLR")
30
+ reg.open(monoversion) do |r|
31
+ @mono_directory = r.read_s("SdkInstallRoot")
32
+ @mono_lib_directory = r.read_s("FrameworkAssemblyDirectory")
33
+ @mono_command = "\\bin\\mono"
34
+ end
35
+ end
36
+ Win32::Registry::HKEY_CURRENT_USER.open("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders") do |reg|
37
+ @config_dir = reg.read_s_expand("AppData")
38
+ end
39
+ rescue Exception => e
40
+ STDERR.puts "Couldn't determine mono location under Windows!"
41
+ STDERR.puts e.inspect
42
+ end
43
+ else
44
+ if ENV['MONO_PREFIX'] != nil then
45
+ @mono_directory = ENV['MONO_PREFIX']
46
+ @mono_lib_directory = File.join(@mono_directory,"lib")
47
+ end
48
+ end
49
+ end
50
+
51
+ # create a file that will be executed before the interpreter starts
52
+ def create_init_script(init_script, name)
53
+ if init_script then
54
+ csconfig = File.join(@config_dir,name)
55
+ FileUtils::mkdir_p(csconfig)
56
+ csfile = File.join(csconfig,@init_script_name);
57
+ File.open(csfile,"w+") do |f|
58
+ f.write init_script
59
+ end
60
+ end
61
+ end
62
+
63
+ # remove the file
64
+ def delete_init_script(init_script, name)
65
+ if init_script then
66
+ csconfig = File.join(@config_dir,name)
67
+ csfile = File.join(csconfig,@init_script_name);
68
+ FileUtils::rm_rf(csfile)
69
+ end
70
+ end
71
+
72
+ # run csharp with an optional initialization script
73
+ def load_csharp(init_script = nil)
74
+ create_init_script(init_script,"csharp")
75
+ puts "Mono executable: \"#{File.join(@mono_directory,@mono_command)}\""
76
+ cs = File.join(@mono_lib_directory,@csharp_command)
77
+ puts "CSharp executable: \"#{cs}\""
78
+ system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{cs}\"")
79
+ delete_init_script("csharp")
80
+ end
81
+
82
+ # run gsharp with an optional initialization script
83
+ def load_gsharp(init_script = nil)
84
+ create_init_script(init_script,"gsharp")
85
+ puts "Mono executable: \"#{File.join(@mono_directory,@mono_command)}\""
86
+ gs = File.join(@mono_lib_directory,@gsharp_command)
87
+ puts "GSharp executable: \"#{gs}\""
88
+ system("\"#{File.join(@mono_directory,@mono_command)}\" \"#{gs}\"")
89
+ delete_init_script("gsharp")
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'shaml/mono_load'
3
+ require 'shaml/command'
4
+
5
+ module Shaml
6
+ SHAML_VERSION="0.5.0"
7
+ TEMPLATEDIR = File.join(File.dirname(__FILE__),"templates")
8
+ Mono = MonoLoader.new
9
+ Command = CommandLoader.new
10
+ end
@@ -0,0 +1,3 @@
1
+ %div
2
+ %h2 Create WebSample
3
+ _ WebSampleForm
@@ -0,0 +1,7 @@
1
+ %div
2
+ %h2 Delete WebSample
3
+ %p Are you sure?
4
+ - using (Html.BeginForm<WebSamplesController>(c => c.DeleteConfirmed(ViewData.Model.Id)))
5
+ = Html.AntiForgeryToken()
6
+ %input{ type="submit" value="Yes" }
7
+ %input{ type="button" name="No" value="No" onclick="javascript:history.go(-1);"}
@@ -0,0 +1,3 @@
1
+ %div
2
+ %h2 Edit WebSample
3
+ _ WebSampleForm
@@ -0,0 +1,24 @@
1
+ %div
2
+ %h2 WebSamples
3
+ - if (ViewContext.TempData["message"] != null)
4
+ %p= ViewContext.TempData["message"]
5
+ %table
6
+ %thead
7
+ %tr
8
+ // TODO: List of properties begin
9
+ %th Property
10
+ // TODO: List of properties end
11
+ %th{ colspan=3 } Action
12
+ %tbody
13
+ - foreach (WebSample websample in ViewData.Model)
14
+ %tr
15
+ // TODO: List of properties begin
16
+ %td= websample.Property
17
+ // TODO: List of properties end
18
+ %td
19
+ = Html.ActionLink<WebSamplesController>( c => c.Show( websample.Id ), "Details ")
20
+ %td
21
+ = Html.ActionLink<WebSamplesController>( c => c.Edit( websample.Id ), "Edit")
22
+ %td
23
+ = Html.ActionLink<WebSamplesController>( c => c.Delete( websample.Id), "Delete")
24
+ %p= Html.ActionLink<WebSamplesController>(c => c.Create(), "Create New WebSample")
@@ -0,0 +1,10 @@
1
+ @type=WebSample
2
+ %div
3
+ %h2 WebSample Details
4
+ %ul
5
+ // TODO: List of properties begin
6
+ %li
7
+ %label{ for="WebSample.Name" } Property:
8
+ %span{ id="WebSample.Name" }
9
+ = ViewData.Model.Property
10
+ // TODO: List of properties end
@@ -0,0 +1,14 @@
1
+ using NHibernate.Validator.Constraints;
2
+ using Shaml.Core.DomainModel;
3
+ using Shaml.Core.PersistenceSupport;
4
+ using System;
5
+
6
+ namespace WebBase.Core
7
+ {
8
+ public class WebSample : Entity
9
+ {
10
+ public WebSample() { }
11
+
12
+ // TODO: Add Properties to the Domain Object
13
+ }
14
+ }
@@ -0,0 +1,21 @@
1
+ using NUnit.Framework;
2
+ using WebBase.Core;
3
+ using Shaml.Testing;
4
+
5
+ namespace Tests.Blog.Core
6
+ {
7
+ [TestFixture]
8
+ public class WebSampleTests
9
+ {
10
+ [Test]
11
+ public void CanCompareWebSamples() {
12
+ WebSample instance = new WebSample();
13
+ EntityIdSetter.SetIdOf<int>(instance, 1);
14
+
15
+ WebSample instanceToCompareTo = new WebSample();
16
+ EntityIdSetter.SetIdOf<int>(instanceToCompareTo, 1);
17
+
18
+ instance.ShouldEqual(instanceToCompareTo);
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,140 @@
1
+ using System.Web.Mvc;
2
+ using WebBase.Core;
3
+ using SharpArch.Core.PersistenceSupport;
4
+ using SharpArch.Core.DomainModel;
5
+ using System.Collections.Generic;
6
+ using System;
7
+ using SharpArch.Web.NHibernate;
8
+ using NHibernate.Validator.Engine;
9
+ using System.Text;
10
+ using SharpArch.Web.CommonValidator;
11
+ using SharpArch.Core;
12
+
13
+ namespace WebBase.Controllers
14
+ {
15
+ [HandleError]
16
+ public class WebSamplesController : Controller
17
+ {
18
+ public WebSamplesController(IRepository<WebSample> websampleRepository) {
19
+ Check.Require(websampleRepository != null, "websampleRepository may not be null");
20
+
21
+ this.websampleRepository = websampleRepository;
22
+ }
23
+
24
+ [Transaction]
25
+ public ActionResult Index() {
26
+ IList<WebSample> websamples = websampleRepository.GetAll();
27
+ return View(websamples);
28
+ }
29
+
30
+ [Transaction]
31
+ public ActionResult Show(int id) {
32
+ WebSample websample = websampleRepository.Get(id);
33
+ return View(websample);
34
+ }
35
+
36
+ public ActionResult Create() {
37
+ WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
38
+ return View(viewModel);
39
+ }
40
+
41
+ [ValidateAntiForgeryToken]
42
+ [Transaction]
43
+ [AcceptVerbs(HttpVerbs.Post)]
44
+ public ActionResult Create(WebSample websample) {
45
+ if (ViewData.ModelState.IsValid && websample.IsValid()) {
46
+ websampleRepository.SaveOrUpdate(websample);
47
+
48
+ TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
49
+ "The websample was successfully created.";
50
+ return RedirectToAction("Index");
51
+ }
52
+
53
+ WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
54
+ viewModel.WebSample = websample;
55
+ return View(viewModel);
56
+ }
57
+
58
+ [Transaction]
59
+ public ActionResult Edit(int id) {
60
+ WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
61
+ viewModel.WebSample = websampleRepository.Get(id);
62
+ return View(viewModel);
63
+ }
64
+
65
+ [ValidateAntiForgeryToken]
66
+ [Transaction]
67
+ [AcceptVerbs(HttpVerbs.Post)]
68
+ public ActionResult Edit(WebSample websample) {
69
+ WebSample websampleToUpdate = websampleRepository.Get(websample.Id);
70
+ TransferFormValuesTo(websampleToUpdate, websample);
71
+
72
+ if (ViewData.ModelState.IsValid && websample.IsValid()) {
73
+ TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
74
+ "The websample was successfully updated.";
75
+ return RedirectToAction("Index");
76
+ }
77
+ else {
78
+ websampleRepository.DbContext.RollbackTransaction();
79
+
80
+ WebSampleFormViewModel viewModel = WebSampleFormViewModel.CreateWebSampleFormViewModel();
81
+ viewModel.WebSample = websample;
82
+ return View(viewModel);
83
+ }
84
+ }
85
+
86
+ private void TransferFormValuesTo(WebSample websampleToUpdate, WebSample websampleFromForm) {
87
+ // TODO: Add copy methods
88
+ }
89
+
90
+ [ValidateAntiForgeryToken]
91
+ [Transaction]
92
+ [AcceptVerbs(HttpVerbs.Post)]
93
+ public ActionResult Delete(int id) {
94
+ string resultMessage = "The websample was successfully deleted.";
95
+ WebSample websampleToDelete = websampleRepository.Get(id);
96
+
97
+ if (websampleToDelete != null) {
98
+ websampleRepository.Delete(websampleToDelete);
99
+
100
+ try {
101
+ websampleRepository.DbContext.CommitChanges();
102
+ }
103
+ catch {
104
+ resultMessage = "A problem was encountered preventing the websample from being deleted. " +
105
+ "Another item likely depends on this websample.";
106
+ websampleRepository.DbContext.RollbackTransaction();
107
+ }
108
+ }
109
+ else {
110
+ resultMessage = "The websample could not be found for deletion. It may already have been deleted.";
111
+ }
112
+
113
+ TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = resultMessage;
114
+ return RedirectToAction("Index");
115
+ }
116
+
117
+ /// <summary>
118
+ /// Holds data to be passed to the WebSample form for creates and edits
119
+ /// </summary>
120
+ public class WebSampleFormViewModel
121
+ {
122
+ private WebSampleFormViewModel() { }
123
+
124
+ /// <summary>
125
+ /// Creation method for creating the view model. Services may be passed to the creation
126
+ /// method to instantiate items such as lists for drop down boxes.
127
+ /// </summary>
128
+ public static WebSampleFormViewModel CreateWebSampleFormViewModel() {
129
+ WebSampleFormViewModel viewModel = new WebSampleFormViewModel();
130
+
131
+ return viewModel;
132
+ }
133
+
134
+ public WebSample WebSample { get; internal set; }
135
+ }
136
+
137
+ private readonly IRepository<WebSample> websampleRepository;
138
+ }
139
+ }
140
+
@@ -0,0 +1,147 @@
1
+ using System;
2
+ using MvcContrib.TestHelper;
3
+ using NUnit.Framework;
4
+ using Rhino.Mocks;
5
+ using Shaml.Core.PersistenceSupport;
6
+ using Shaml.Testing;
7
+ using System.Collections.Generic;
8
+ using System.Web.Mvc;
9
+ using WebBase;
10
+ using WebBase.Config;
11
+ using WebBase.Core;
12
+ using WebBase.Controllers;
13
+
14
+ namespace Tests.Blog.Web.Controllers
15
+ {
16
+ [TestFixture]
17
+ public class WebSamplesControllerTests
18
+ {
19
+ [SetUp]
20
+ public void SetUp() {
21
+ ServiceLocatorInitializer.Init();
22
+ controller = new WebSamplesController(CreateMockWebSampleRepository());
23
+ }
24
+
25
+ /// <summary>
26
+ /// Add a couple of objects to the list within CreateWebSamples and change the
27
+ /// "ShouldEqual(0)" within this test to the respective number.
28
+ /// </summary>
29
+ [Test]
30
+ public void CanListWebSamples() {
31
+ ViewResult result = controller.Index().AssertViewRendered();
32
+
33
+ result.ViewData.Model.ShouldNotBeNull();
34
+ (result.ViewData.Model as List<WebSample>).Count.ShouldEqual(0);
35
+ }
36
+
37
+ [Test]
38
+ public void CanShowWebSample() {
39
+ ViewResult result = controller.Show(1).AssertViewRendered();
40
+
41
+ result.ViewData.ShouldNotBeNull();
42
+
43
+ (result.ViewData.Model as WebSample).Id.ShouldEqual(1);
44
+ }
45
+
46
+ [Test]
47
+ public void CanInitWebSampleCreation() {
48
+ ViewResult result = controller.Create().AssertViewRendered();
49
+
50
+ result.ViewData.Model.ShouldNotBeNull();
51
+ result.ViewData.Model.ShouldBeOfType(typeof(WebSamplesController.WebSampleFormViewModel));
52
+ (result.ViewData.Model as WebSamplesController.WebSampleFormViewModel).WebSample.ShouldBeNull();
53
+ }
54
+
55
+ [Test]
56
+ public void CanEnsureWebSampleCreationIsValid() {
57
+ WebSample websampleFromForm = new WebSample();
58
+ ViewResult result = controller.Create(websampleFromForm).AssertViewRendered();
59
+
60
+ result.ViewData.Model.ShouldNotBeNull();
61
+ result.ViewData.Model.ShouldBeOfType(typeof(WebSamplesController.WebSampleFormViewModel));
62
+ }
63
+
64
+ [Test]
65
+ public void CanCreateWebSample() {
66
+ WebSample websampleFromForm = CreateTransientWebSample();
67
+ RedirectToRouteResult redirectResult = controller.Create(websampleFromForm)
68
+ .AssertActionRedirect().ToAction("Index");
69
+ controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
70
+ .ShouldContain("was successfully created");
71
+ }
72
+
73
+ [Test]
74
+ public void CanUpdateWebSample() {
75
+ WebSample websampleFromForm = CreateTransientWebSample();
76
+ EntityIdSetter.SetIdOf<int>(websampleFromForm, 1);
77
+ RedirectToRouteResult redirectResult = controller.Edit(websampleFromForm)
78
+ .AssertActionRedirect().ToAction("Index");
79
+ controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
80
+ .ShouldContain("was successfully updated");
81
+ }
82
+
83
+ [Test]
84
+ public void CanInitWebSampleEdit() {
85
+ ViewResult result = controller.Edit(1).AssertViewRendered();
86
+
87
+ result.ViewData.Model.ShouldNotBeNull();
88
+ result.ViewData.Model.ShouldBeOfType(typeof(WebSamplesController.WebSampleFormViewModel));
89
+ (result.ViewData.Model as WebSamplesController.WebSampleFormViewModel).WebSample.Id.ShouldEqual(1);
90
+ }
91
+
92
+ [Test]
93
+ public void CanDeleteWebSample() {
94
+ RedirectToRouteResult redirectResult = controller.Delete(1)
95
+ .AssertActionRedirect().ToAction("Index");
96
+
97
+ controller.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
98
+ .ShouldContain("was successfully deleted");
99
+ }
100
+
101
+ #region Create Mock WebSample Repository
102
+
103
+ private IRepository<WebSample> CreateMockWebSampleRepository() {
104
+
105
+ IRepository<WebSample> mockedRepository = MockRepository.GenerateMock<IRepository<WebSample>>();
106
+ mockedRepository.Expect(mr => mr.GetAll()).Return(CreateWebSamples());
107
+ mockedRepository.Expect(mr => mr.Get(1)).IgnoreArguments().Return(CreateWebSample());
108
+ mockedRepository.Expect(mr => mr.SaveOrUpdate(null)).IgnoreArguments().Return(CreateWebSample());
109
+ mockedRepository.Expect(mr => mr.Delete(null)).IgnoreArguments();
110
+
111
+ IDbContext mockedDbContext = MockRepository.GenerateStub<IDbContext>();
112
+ mockedDbContext.Stub(c => c.CommitChanges());
113
+ mockedRepository.Stub(mr => mr.DbContext).Return(mockedDbContext);
114
+
115
+ return mockedRepository;
116
+ }
117
+
118
+ private WebSample CreateWebSample() {
119
+ WebSample websample = CreateTransientWebSample();
120
+ EntityIdSetter.SetIdOf<int>(websample, 1);
121
+ return websample;
122
+ }
123
+
124
+ private List<WebSample> CreateWebSamples() {
125
+ List<WebSample> websamples = new List<WebSample>();
126
+
127
+ // Create a number of domain object instances here and add them to the list
128
+
129
+ return websamples;
130
+ }
131
+
132
+ #endregion
133
+
134
+ /// <summary>
135
+ /// Creates a valid, transient WebSample; typical of something retrieved back from a form submission
136
+ /// </summary>
137
+ private WebSample CreateTransientWebSample() {
138
+ WebSample websample = new WebSample() {
139
+ //TODO: Create the properties of the object
140
+ };
141
+
142
+ return websample;
143
+ }
144
+
145
+ private WebSamplesController controller;
146
+ }
147
+ }
@@ -0,0 +1,16 @@
1
+ @type=WebSample
2
+ = Html.ValidationSummary()
3
+ - using (Html.BeginForm())
4
+ = Html.AntiForgeryToken()
5
+ = Html.Hidden("id", (ViewData.Model == null) ? 0 : (ViewData.Model).Id)
6
+ %ul
7
+ // TODO: List of properties begin
8
+ %li
9
+ %label{ for="WebSample_Property" }Property:
10
+ %div
11
+ = Html.TextBox("WebSample.Property", ViewData.Model != null ? ViewData.Model.Property.ToString() : "")
12
+ = Html.ValidationMessage("WebSample.Property")
13
+ // TODO: List of properties end
14
+ %li
15
+ %input{ type="submit" name="btnSave" value="Save WebSample"}/
16
+ %button{ name="btnCancel" onClick="window.location.href = '/WebSamples';"} Cancel
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shaml
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ - alpha
10
+ version: 0.5.0.alpha
11
+ platform: ruby
12
+ authors:
13
+ - Zsolt Sz. Sztupak
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-04-01 00:00:00 +02:00
19
+ default_executable: shaml
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rubyzip
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 9
31
+ - 1
32
+ version: 0.9.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: compass
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ - 6
45
+ - 15
46
+ version: 0.6.15
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Shaml is an ASP.NET MVC 2 framework with NHibernate 2.1 for mono 2.4.4+
50
+ email: mail@sztupy.hu
51
+ executables:
52
+ - shaml
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - bin/shaml
59
+ - lib/shaml/templates/shaml_base_template.dat
60
+ - lib/shaml/command.rb
61
+ - lib/shaml/mono_load.rb
62
+ - lib/shaml/shaml.rb
63
+ - lib/shaml/templates/Create.haml
64
+ - lib/shaml/templates/Delete.haml
65
+ - lib/shaml/templates/Edit.haml
66
+ - lib/shaml/templates/Index.haml
67
+ - lib/shaml/templates/Show.haml
68
+ - lib/shaml/templates/_WebSampleForm.haml
69
+ - lib/shaml/templates/WebSample.cs
70
+ - lib/shaml/templates/WebSamplesController.cs
71
+ - lib/shaml/templates/WebSamplesControllerTests.cs
72
+ - lib/shaml/templates/WebSampleTests.cs
73
+ has_rdoc: true
74
+ homepage: http://code.google.com/p/shaml-architecture/
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project: shaml
99
+ rubygems_version: 1.3.6
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: ASP.NET MVC on mono
103
+ test_files: []
104
+