sztupy-shaml 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/shaml +2 -0
- data/lib/shaml.rb +158 -0
- data/lib/templates/Create.haml +3 -0
- data/lib/templates/Delete.haml +7 -0
- data/lib/templates/Edit.haml +3 -0
- data/lib/templates/Index.haml +24 -0
- data/lib/templates/Show.haml +9 -0
- data/lib/templates/WebSample.cs +16 -0
- data/lib/templates/WebSampleTests.cs +20 -0
- data/lib/templates/WebSamplesController.cs +130 -0
- data/lib/templates/WebSamplesControllerTests.cs +147 -0
- data/lib/templates/_WebSampleForm.haml +16 -0
- data/lib/templates/shaml_base_template.zip +0 -0
- metadata +74 -0
data/bin/shaml
ADDED
data/lib/shaml.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'zip/zip'
|
3
|
+
|
4
|
+
SHAML_VERSION="0.1"
|
5
|
+
|
6
|
+
TEMPLATEDIR = File.join(File.dirname(__FILE__),"templates")
|
7
|
+
|
8
|
+
def camelcase(phrase)
|
9
|
+
phrase.gsub(/^[a-z]|[ _]+[a-z]/) { |a| a.upcase }.gsub(/[ _]/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def unzip_file(file, destination)
|
14
|
+
Zip::ZipFile.open(file) { |zip_file|
|
15
|
+
zip_file.each { |f|
|
16
|
+
f_path=File.join(destination, f.name)
|
17
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
18
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def convert_file(file, appname, modelname, propertydescriptor)
|
24
|
+
out = ""
|
25
|
+
pstring = ""
|
26
|
+
insideprop = false
|
27
|
+
file.each_line do |line|
|
28
|
+
if insideprop then
|
29
|
+
if line.strip=="__END__PROPERTY__" then
|
30
|
+
propertydescriptor.split(";").each do |property|
|
31
|
+
p = property.split(":")
|
32
|
+
out << pstring.gsub("PropertyType",p[1]).gsub("Property",p[0])
|
33
|
+
end
|
34
|
+
insideprop = false
|
35
|
+
else
|
36
|
+
pstring << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
|
37
|
+
end
|
38
|
+
else
|
39
|
+
if line.strip=="__BEGIN__PROPERTY__" then
|
40
|
+
pstring = ""
|
41
|
+
insideprop = true
|
42
|
+
else
|
43
|
+
out << line.gsub("WebBase",appname).gsub("WebSample", camelcase(modelname)).gsub("websample", modelname);
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
out
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_file(from,to,appname,modelname,propertydescriptor)
|
51
|
+
|
52
|
+
outfname = to.gsub("WebSample",camelcase(modelname))
|
53
|
+
FileUtils.mkdir_p(File.dirname(outfname))
|
54
|
+
File.open(from,"rb") do |infile|
|
55
|
+
File.open(outfname,"wb+") do |outfile|
|
56
|
+
puts "Writing #{outfname}"
|
57
|
+
outfile.write convert_file(infile.read,appname,modelname,propertydescriptor)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
if ARGV.count == 0 then
|
63
|
+
puts "S#aml architecture: ASP.NET MVC and NHibernate on mono 2.4+"
|
64
|
+
puts " version: #{SHAML_VERSION}"
|
65
|
+
puts
|
66
|
+
puts "Usage:"
|
67
|
+
puts " shaml command [parameters]"
|
68
|
+
puts
|
69
|
+
puts "Where command might be:"
|
70
|
+
puts " generate"
|
71
|
+
puts " app AppName : Create new shaml application"
|
72
|
+
puts " resource ResName [desc] : Create new CRUD resource with"
|
73
|
+
puts " a model, a view and a controller"
|
74
|
+
puts " controller Controller : Create a standalone controller"
|
75
|
+
puts " model Model [desc] : Create a standalone model"
|
76
|
+
puts
|
77
|
+
puts "Examples: "
|
78
|
+
puts " shaml generate app Blog"
|
79
|
+
puts " shaml generate resource Post"
|
80
|
+
puts
|
81
|
+
puts "The optional [desc] parameter describes the base schema"
|
82
|
+
puts "of the model. Here is an example how it looks like:"
|
83
|
+
puts " name:string;email:string;birthdate:DateTime"
|
84
|
+
else
|
85
|
+
command = ARGV.shift
|
86
|
+
case command
|
87
|
+
when "generate" then
|
88
|
+
type = ARGV.shift
|
89
|
+
name = ARGV.shift
|
90
|
+
if name then
|
91
|
+
case type
|
92
|
+
when "app" then
|
93
|
+
unzip_file(File.join(TEMPLATEDIR,"shaml_base_template.zip"), ".shaml_extract_temp")
|
94
|
+
Dir.glob(".shaml_extract_temp/**/*").each do |filename|
|
95
|
+
infname = filename
|
96
|
+
outfname = filename.gsub("WebBase",name).gsub(".shaml_extract_temp",name);
|
97
|
+
FileUtils.mkdir_p(File.dirname(outfname))
|
98
|
+
unless File.directory?(infname)
|
99
|
+
File.open(infname,"rb") do |infile|
|
100
|
+
File.open(outfname,"wb+") do |outfile|
|
101
|
+
puts "Writing #{outfname}"
|
102
|
+
outfile.write infile.read.gsub("WebBase",name);
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
FileUtils.rm_rf ".shaml_extract_temp"
|
108
|
+
when "resource"
|
109
|
+
desc = ARGV.shift || nil
|
110
|
+
appname = Dir.glob("*.sln").first.gsub(".sln","");
|
111
|
+
if appname.nil?
|
112
|
+
puts 'S#aml ERROR: solution file not found'
|
113
|
+
exit
|
114
|
+
end
|
115
|
+
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join(appname,"App","Models","WebSample.cs"),appname,name,desc)
|
116
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join(appname,"App","Controllers","WebSamplesController.cs"),appname,name,desc)
|
117
|
+
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join(appname,"App","Views","WebSample","_WebSampleForm.haml"),appname,name,desc)
|
118
|
+
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join(appname,"App","Views","WebSample","Create.haml"),appname,name,desc)
|
119
|
+
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join(appname,"App","Views","WebSample","Delete.haml"),appname,name,desc)
|
120
|
+
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join(appname,"App","Views","WebSample","Edit.haml"),appname,name,desc)
|
121
|
+
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join(appname,"App","Views","WebSample","Index.haml"),appname,name,desc)
|
122
|
+
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join(appname,"App","Views","WebSample","Show.haml"),appname,name,desc)
|
123
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join(appname+".Tests","Tests","Core","WebSampleTests.cs"),appname,name,desc)
|
124
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join(appname+".Tests","Tests","Web","Controllers","WebSamplesControllerTests.cs"),appname,name,desc)
|
125
|
+
when "model"
|
126
|
+
desc = ARGV.shift || nil
|
127
|
+
appname = Dir.glob("*.sln").first.gsub(".sln","");
|
128
|
+
if appname.nil?
|
129
|
+
puts 'S#aml ERROR: solution file not found'
|
130
|
+
exit
|
131
|
+
end
|
132
|
+
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join(appname,"App","Models","WebSample.cs"),appname,name,desc)
|
133
|
+
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join(appname+".Tests","Tests","Core","WebSampleTests.cs"),appname,name,desc)
|
134
|
+
when "controller"
|
135
|
+
desc = ARGV.shift || nil
|
136
|
+
appname = Dir.glob("*.sln").first.gsub(".sln","");
|
137
|
+
if appname.nil?
|
138
|
+
puts 'S#aml ERROR: solution file not found'
|
139
|
+
exit
|
140
|
+
end
|
141
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join(appname,"App","Controllers","WebSamplesController.cs"),appname,name,desc)
|
142
|
+
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join(appname,"App","Views","WebSample","_WebSampleForm.haml"),appname,name,desc)
|
143
|
+
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join(appname,"App","Views","WebSample","Create.haml"),appname,name,desc)
|
144
|
+
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join(appname,"App","Views","WebSample","Delete.haml"),appname,name,desc)
|
145
|
+
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join(appname,"App","Views","WebSample","Edit.haml"),appname,name,desc)
|
146
|
+
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join(appname,"App","Views","WebSample","Index.haml"),appname,name,desc)
|
147
|
+
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join(appname,"App","Views","WebSample","Show.haml"),appname,name,desc)
|
148
|
+
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join(appname+".Tests","Tests","Web","Controllers","WebSamplesControllerTests.cs"),appname,name,desc)
|
149
|
+
else
|
150
|
+
puts 'S#aml ERROR: unknown generate argument'
|
151
|
+
end
|
152
|
+
else
|
153
|
+
puts 'S#aml ERROR: no name specified'
|
154
|
+
end
|
155
|
+
else
|
156
|
+
puts 'S#aml ERROR: unknown command'
|
157
|
+
end
|
158
|
+
end
|
@@ -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,24 @@
|
|
1
|
+
%div
|
2
|
+
%h2 WebSamples
|
3
|
+
- if (ViewContext.TempData["message"] != null)
|
4
|
+
%p= ViewContext.TempData["message"]
|
5
|
+
%table
|
6
|
+
%thead
|
7
|
+
%tr
|
8
|
+
%th Name
|
9
|
+
%th CreatedAt
|
10
|
+
%th CreatorOwner
|
11
|
+
%th{ colspan=3 } Action
|
12
|
+
%tbody
|
13
|
+
- foreach (WebSample websample in ViewData.Model)
|
14
|
+
%tr
|
15
|
+
__BEGIN__PROPERTY__
|
16
|
+
%td= websample.Property
|
17
|
+
__END__PROPERTY__
|
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,16 @@
|
|
1
|
+
using NHibernate.Validator;
|
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
|
+
__BEGIN__PROPERTY__
|
13
|
+
public virtual PropertyType Property { get; set; }
|
14
|
+
__END__PROPERTY__
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
using NUnit.Framework;
|
2
|
+
using WebBase.Core;
|
3
|
+
using NUnit.Framework.SyntaxHelpers;
|
4
|
+
using Shaml.Testing;
|
5
|
+
|
6
|
+
namespace Tests.Blog.Core
|
7
|
+
{
|
8
|
+
[TestFixture]
|
9
|
+
public class WebSampleTests
|
10
|
+
{
|
11
|
+
[Test]
|
12
|
+
public void CanCompareWebSamples() {
|
13
|
+
WebSample instance = new WebSample();
|
14
|
+
|
15
|
+
WebSample instanceToCompareTo = new WebSample();
|
16
|
+
|
17
|
+
Assert.That(instance.Equals(instanceToCompareTo));
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
using System.Web.Mvc;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Text;
|
4
|
+
using System;
|
5
|
+
using Shaml.Core;
|
6
|
+
using Shaml.Core.DomainModel;
|
7
|
+
using Shaml.Core.PersistenceSupport;
|
8
|
+
using Shaml.Web.NHibernate;
|
9
|
+
using Shaml.Web.CommonValidator;
|
10
|
+
using NHibernate.Validator.Engine;
|
11
|
+
using WebBase.Core;
|
12
|
+
using Shaml.Data.NHibernate;
|
13
|
+
|
14
|
+
namespace WebBase.Controllers
|
15
|
+
{
|
16
|
+
[HandleError]
|
17
|
+
[GenericLogger]
|
18
|
+
public class WebSamplesController : Controller
|
19
|
+
{
|
20
|
+
private readonly IRepository<WebSample> websampleRepository;
|
21
|
+
|
22
|
+
public WebSamplesController()
|
23
|
+
{
|
24
|
+
websampleRepository = new Repository<WebSample>();
|
25
|
+
}
|
26
|
+
|
27
|
+
public WebSamplesController(IRepository<WebSample> rep)
|
28
|
+
{
|
29
|
+
websampleRepository = rep;
|
30
|
+
}
|
31
|
+
|
32
|
+
[Transaction]
|
33
|
+
public ActionResult Index() {
|
34
|
+
IList<WebSample> websamples = websampleRepository.GetAll();
|
35
|
+
return View(websamples);
|
36
|
+
}
|
37
|
+
|
38
|
+
[Transaction]
|
39
|
+
public ActionResult Show(int id) {
|
40
|
+
WebSample websample = websampleRepository.Get(id);
|
41
|
+
return View(websample);
|
42
|
+
}
|
43
|
+
|
44
|
+
public ActionResult Create() {
|
45
|
+
return View();
|
46
|
+
}
|
47
|
+
|
48
|
+
//[ValidateAntiForgeryToken]
|
49
|
+
[Transaction]
|
50
|
+
[AcceptVerbs(HttpVerbs.Post)]
|
51
|
+
public ActionResult Create(WebSample websample) {
|
52
|
+
if (websample.IsValid()) {
|
53
|
+
websampleRepository.SaveOrUpdate(websample);
|
54
|
+
|
55
|
+
TempData["message"] = "The websample was successfully created.";
|
56
|
+
return RedirectToAction("Index");
|
57
|
+
}
|
58
|
+
|
59
|
+
MvcValidationAdapter.TransferValidationMessagesTo(ViewData.ModelState,
|
60
|
+
websample.ValidationResults());
|
61
|
+
return View();
|
62
|
+
}
|
63
|
+
|
64
|
+
[Transaction]
|
65
|
+
public ActionResult Edit(int id) {
|
66
|
+
WebSample websample = websampleRepository.Get(id);
|
67
|
+
return View(websample);
|
68
|
+
}
|
69
|
+
|
70
|
+
//[ValidateAntiForgeryToken]
|
71
|
+
[Transaction]
|
72
|
+
[AcceptVerbs(HttpVerbs.Post)]
|
73
|
+
public ActionResult Edit(int id, [ModelBinder(typeof(DefaultModelBinder))] WebSample websample) {
|
74
|
+
WebSample websampleToUpdate = websampleRepository.Get(id);
|
75
|
+
TransferFormValuesTo(websampleToUpdate, websample);
|
76
|
+
|
77
|
+
if (websampleToUpdate.IsValid()) {
|
78
|
+
TempData["message"] = "The websample was successfully updated.";
|
79
|
+
return RedirectToAction("Index");
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
websampleRepository.DbContext.RollbackTransaction();
|
83
|
+
MvcValidationAdapter.TransferValidationMessagesTo(ViewData.ModelState,
|
84
|
+
websampleToUpdate.ValidationResults());
|
85
|
+
return View(websampleToUpdate);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
private void TransferFormValuesTo(WebSample websampleToUpdate, WebSample websampleFromForm) {
|
90
|
+
__BEGIN__PROPERTY__
|
91
|
+
websampleToUpdate.Property = websampleFromForm.Property;
|
92
|
+
__END__PROPERTY__
|
93
|
+
}
|
94
|
+
|
95
|
+
[AcceptVerbs(HttpVerbs.Get)]
|
96
|
+
public ActionResult Delete(int id)
|
97
|
+
{
|
98
|
+
WebSample websampleToDelete = websampleRepository.Get(id);
|
99
|
+
return View(websampleToDelete);
|
100
|
+
}
|
101
|
+
|
102
|
+
//[ValidateAntiForgeryToken]
|
103
|
+
[Transaction]
|
104
|
+
[AcceptVerbs(HttpVerbs.Post)]
|
105
|
+
public ActionResult DeleteConfirmed(int id) {
|
106
|
+
string resultMessage = "The websample was successfully deleted.";
|
107
|
+
WebSample websampleToDelete = websampleRepository.Get(id);
|
108
|
+
|
109
|
+
if (websampleToDelete != null) {
|
110
|
+
websampleRepository.Delete(websampleToDelete);
|
111
|
+
|
112
|
+
try {
|
113
|
+
websampleRepository.DbContext.CommitChanges();
|
114
|
+
}
|
115
|
+
catch {
|
116
|
+
resultMessage = "A problem was encountered preventing the websample from being deleted. " +
|
117
|
+
"Another item likely depends on this websample.";
|
118
|
+
websampleRepository.DbContext.RollbackTransaction();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
resultMessage = "The websample could not be found for deletion. It may already have been deleted.";
|
123
|
+
}
|
124
|
+
|
125
|
+
TempData["Message"] = resultMessage;
|
126
|
+
return RedirectToAction("Index");
|
127
|
+
}
|
128
|
+
|
129
|
+
}
|
130
|
+
}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
using System;
|
2
|
+
using MvcContrib.TestHelper;
|
3
|
+
using NUnit.Framework;
|
4
|
+
using Rhino.Mocks;
|
5
|
+
using NUnit.Framework.SyntaxHelpers;
|
6
|
+
using Shaml.Core.PersistenceSupport;
|
7
|
+
using Shaml.Testing;
|
8
|
+
using System.Collections.Generic;
|
9
|
+
using System.Web.Mvc;
|
10
|
+
using WebBase.Core;
|
11
|
+
using WebBase.Controllers;
|
12
|
+
|
13
|
+
namespace Tests.Blog.Web.Controllers
|
14
|
+
{
|
15
|
+
[TestFixture]
|
16
|
+
public class WebSamplesControllerTests
|
17
|
+
{
|
18
|
+
[SetUp]
|
19
|
+
public void SetUp() {
|
20
|
+
controller = new WebSamplesController(CreateMockWebSampleRepository());
|
21
|
+
}
|
22
|
+
|
23
|
+
/// <summary>
|
24
|
+
/// Add a couple of objects to the list within CreateWebSamples and change the
|
25
|
+
/// "Is.EqualTo(0)" within this test to the respective number.
|
26
|
+
/// </summary>
|
27
|
+
[Test]
|
28
|
+
public void CanListWebSamples() {
|
29
|
+
ViewResult result = controller.Index().AssertViewRendered();
|
30
|
+
|
31
|
+
Assert.That(result.ViewData.Model as List<WebSample>, Is.Not.Null);
|
32
|
+
Assert.That((result.ViewData.Model as List<WebSample>).Count, Is.EqualTo(0));
|
33
|
+
}
|
34
|
+
|
35
|
+
[Test]
|
36
|
+
public void CanShowWebSample() {
|
37
|
+
ViewResult result = controller.Show(1).AssertViewRendered();
|
38
|
+
|
39
|
+
Assert.That(result.ViewData.Model as WebSample, Is.Not.Null);
|
40
|
+
Assert.That((result.ViewData.Model as WebSample).Id, Is.EqualTo(1));
|
41
|
+
}
|
42
|
+
|
43
|
+
[Test]
|
44
|
+
public void CanInitWebSampleCreation() {
|
45
|
+
ViewResult result = controller.Create().AssertViewRendered();
|
46
|
+
|
47
|
+
Assert.That(result.ViewData.Model as WebSample, Is.Null);
|
48
|
+
}
|
49
|
+
|
50
|
+
[Test]
|
51
|
+
public void CanEnsureWebSampleCreationIsValid() {
|
52
|
+
WebSample websampleFromForm = new WebSample();
|
53
|
+
ViewResult result = controller.Create(websampleFromForm).AssertViewRendered();
|
54
|
+
|
55
|
+
Assert.That(result.ViewData.Model as WebSample, Is.Null);
|
56
|
+
Assert.That(result.ViewData.ModelState.Count, Is.GreaterThan(0));
|
57
|
+
|
58
|
+
// Example validation message test for lower level testing
|
59
|
+
// Assert.That(result.ViewData.ModelState["WebSample.Name"].Errors[0].ErrorMessage, Is.Not.Empty);
|
60
|
+
}
|
61
|
+
|
62
|
+
[Test]
|
63
|
+
public void CanCreateWebSample() {
|
64
|
+
WebSample websampleFromForm = CreateTransientWebSample();
|
65
|
+
RedirectToRouteResult redirectResult = controller.Create(websampleFromForm)
|
66
|
+
.AssertActionRedirect().ToAction("Index");
|
67
|
+
Assert.That(controller.TempData["message"].ToString().Contains("was successfully created"));
|
68
|
+
}
|
69
|
+
|
70
|
+
[Test]
|
71
|
+
public void CanUpdateWebSample() {
|
72
|
+
WebSample websampleFromForm = CreateTransientWebSample();
|
73
|
+
RedirectToRouteResult redirectResult = controller.Edit(1, websampleFromForm)
|
74
|
+
.AssertActionRedirect().ToAction("Index");
|
75
|
+
Assert.That(controller.TempData["message"].ToString().Contains("was successfully updated"));
|
76
|
+
}
|
77
|
+
|
78
|
+
[Test]
|
79
|
+
public void CanInitWebSampleEdit() {
|
80
|
+
ViewResult result = controller.Edit(1).AssertViewRendered();
|
81
|
+
|
82
|
+
Assert.That(result.ViewData.Model as WebSample, Is.Not.Null);
|
83
|
+
Assert.That((result.ViewData.Model as WebSample).Id, Is.EqualTo(1));
|
84
|
+
}
|
85
|
+
|
86
|
+
[Test]
|
87
|
+
public void CanDeleteWebSample() {
|
88
|
+
RedirectToRouteResult redirectResult = controller.DeleteConfirmed(1)
|
89
|
+
.AssertActionRedirect().ToAction("Index");
|
90
|
+
Assert.That(controller.TempData["message"].ToString().Contains("was successfully deleted"));
|
91
|
+
}
|
92
|
+
|
93
|
+
#region Create Mock WebSample Repository
|
94
|
+
|
95
|
+
private IRepository<WebSample> CreateMockWebSampleRepository() {
|
96
|
+
MockRepository mocks = new MockRepository();
|
97
|
+
|
98
|
+
IRepository<WebSample> mockedRepository = mocks.StrictMock<IRepository<WebSample>>();
|
99
|
+
Expect.Call(mockedRepository.GetAll())
|
100
|
+
.Return(CreateWebSamples());
|
101
|
+
Expect.Call(mockedRepository.Get(1)).IgnoreArguments()
|
102
|
+
.Return(CreateWebSample());
|
103
|
+
Expect.Call(mockedRepository.SaveOrUpdate(null)).IgnoreArguments()
|
104
|
+
.Return(CreateWebSample());
|
105
|
+
Expect.Call(delegate { mockedRepository.Delete(null); }).IgnoreArguments();
|
106
|
+
|
107
|
+
IDbContext mockedDbContext = mocks.StrictMock<IDbContext>();
|
108
|
+
Expect.Call(delegate { mockedDbContext.CommitChanges(); });
|
109
|
+
SetupResult.For(mockedRepository.DbContext).Return(mockedDbContext);
|
110
|
+
|
111
|
+
mocks.Replay(mockedRepository);
|
112
|
+
|
113
|
+
return mockedRepository;
|
114
|
+
}
|
115
|
+
|
116
|
+
private WebSample CreateWebSample() {
|
117
|
+
WebSample websample = CreateTransientWebSample();
|
118
|
+
EntityIdSetter.SetIdOf<int>(websample, 1);
|
119
|
+
return websample;
|
120
|
+
}
|
121
|
+
|
122
|
+
private List<WebSample> CreateWebSamples() {
|
123
|
+
List<WebSample> websamples = new List<WebSample>();
|
124
|
+
|
125
|
+
// Create a number of websample object instances here and add them to the list
|
126
|
+
|
127
|
+
return websamples;
|
128
|
+
}
|
129
|
+
|
130
|
+
#endregion
|
131
|
+
|
132
|
+
/// <summary>
|
133
|
+
/// Creates a valid, transient WebSample; typical of something retrieved back from a form submission
|
134
|
+
/// </summary>
|
135
|
+
private WebSample CreateTransientWebSample() {
|
136
|
+
WebSample websample = new WebSample() {
|
137
|
+
__BEGIN__PROPERTY__
|
138
|
+
Property = new PropertyType(),
|
139
|
+
__END__PROPERTY__
|
140
|
+
};
|
141
|
+
|
142
|
+
return websample;
|
143
|
+
}
|
144
|
+
|
145
|
+
private WebSamplesController controller;
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
= Html.ValidationSummary()
|
2
|
+
|
3
|
+
- using (Html.BeginForm())
|
4
|
+
/= Html.AntiForgeryToken()
|
5
|
+
= Html.Hidden("id", (ViewData.Model == null) ? 0 : ((WebSample)ViewData.Model).Id)
|
6
|
+
%ul
|
7
|
+
__BEGIN__PROPERTY__
|
8
|
+
%li
|
9
|
+
%label{ for="WebSample_Property" }Name:
|
10
|
+
%div
|
11
|
+
= Html.TextBox("WebSample.Property", (ViewData.Model != null) ? ((WebSample)ViewData.Model).Property.ToString() : "")
|
12
|
+
= Html.ValidationMessage("WebSample.Property")
|
13
|
+
__END__PROPERTY__
|
14
|
+
%li
|
15
|
+
%input{ type="submit" name="btnSave" value="Save WebSample"}/
|
16
|
+
%button{ name="btnCancel" onClick="window.location.href = '/WebSamples';"} Cancel
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sztupy-shaml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zsolt Sz. Sztupak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-18 00:00:00 -07:00
|
13
|
+
default_executable: shaml
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: chriseppstein-compass
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.6.15
|
24
|
+
version:
|
25
|
+
description: Shaml is an ASP.NET MVC framework with NHibernate for mono 2.4+
|
26
|
+
email: mail@sztupy.hu
|
27
|
+
executables:
|
28
|
+
- shaml
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/shaml.rb
|
35
|
+
- bin/shaml
|
36
|
+
- lib/templates/_WebSampleForm.haml
|
37
|
+
- lib/templates/Create.haml
|
38
|
+
- lib/templates/Delete.haml
|
39
|
+
- lib/templates/Edit.haml
|
40
|
+
- lib/templates/Index.haml
|
41
|
+
- lib/templates/shaml_base_template.zip
|
42
|
+
- lib/templates/Show.haml
|
43
|
+
- lib/templates/WebSample.cs
|
44
|
+
- lib/templates/WebSamplesController.cs
|
45
|
+
- lib/templates/WebSamplesControllerTests.cs
|
46
|
+
- lib/templates/WebSampleTests.cs
|
47
|
+
has_rdoc: false
|
48
|
+
homepage: http://code.google.com/p/shaml-architecture/
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project: shaml
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: ASP.NET MVC on mono
|
73
|
+
test_files: []
|
74
|
+
|